How do I get the column headers of a table in a matrix?
Updated code to output the entire table (headers and data).

Try this: 

{% set entry = craft.entries.section('sectionHandle').first %}

{% for block in entry.matrixFieldHandle %}

    {% for field in block.getFieldLayout().getFields() %}

        {% set type = field.getField().type %}

        {% switch type %}
            {% case 'Table' %}

                &lt;h3&gt;{{ field.getField().name }}&lt;/h3&gt;

                &lt;table&gt;
                    &lt;thead&gt;
                        &lt;tr&gt;
                            {% set columns = field.getField().settings.columns %}
                            {% for col in columns %}        
                                &lt;th&gt;{{ col.heading }}&lt;/th&gt;
                            {% endfor %}
                        &lt;/tr&gt;
                    &lt;/thead&gt;
                    &lt;tbody&gt;
                            {% set handle = field.getField().handle %}
                            {% set tableData = block[handle] %}
                            {% for row in tableData %}
                                &lt;tr&gt;
                                    {% for key, col in row if key|slice(0,3) == 'col' %}
                                        &lt;td&gt;{{ col }}&lt;/td&gt;
                                    {% endfor %}
                                &lt;/tr&gt;
                            {% endfor %}
                    &lt;/tbody&gt;
                &lt;/table&gt;

        {% endswitch %}

    {% endfor %}

{% endfor %}