How to add a button in the header of a table form?
Finally, I did it this way:
if (some condition) {
  $data = [
    '#type'     =&gt; 'inline_template',
    '#template' =&gt; '&lt;input type=&quot;submit&quot; id=&quot;edit-toggle&quot; name=&quot;button&quot; value=&quot;{{ foo }}&quot; class=&quot;button js-form-submit form-submit&quot;&gt;',
    '#context'  =&gt; ['foo' =&gt; $this-&gt;t('Toggle')],
  ];
}
else {
  $data = '';
}

$form['inscriptions'] = [
  '#type'   =&gt; 'table',
  '#header' =&gt; [
    [
      'data'    =&gt; $data,
      'colspan' =&gt; 2,
    ],
    [
      'data'    =&gt; 'Distribution',
      'colspan' =&gt; 2,
    ],
    [
      'data'    =&gt; 'Réserve',
      'colspan' =&gt; 2,
    ],
    [
      'data'    =&gt; 'Référent',
      'colspan' =&gt; 2,
    ],
  ],
  '#id'     =&gt; 'planningofdistributions',
  '#sticky' =&gt; TRUE,
];