How do I list the tag groups that are actually in use?
You could use the group filter to group your tags by tag groups:

{% set entries = craft.entries.section('gallery').limit(null) %}

&lt;ul&gt;

    {# Get all the tags related to our gallery entries and group them by tag group #}
    {% set allGalleryTags = craft.tags.relatedTo(entries)|group('group') %}

    {# Loop the tag groups #}
    {% for tagGroup, tagsInGroup in allGalleryTags %}

        &lt;li&gt;
            &lt;h2&gt;{{ tagGroup }}&lt;/h2&gt;
            &lt;ul&gt;

                {# Loop the tags of this group #}
                {% for tag in tagsInGroup %}
                    &lt;li&gt;{{ tag.name }}&lt;/li&gt;
                {% endfor %}

            &lt;/ul&gt;
        &lt;/li&gt;

    {% endfor %}

&lt;/ul&gt;