1

In the following example, it looks like that the \worldflag command pushes the flags to the top of the table cells, creating some vertical whitespace. How to vertically align the flags to the text within the table, and therefore removing the vertical whitespace inside the table cells?

\documentclass{article}
\usepackage[a4paper,margin=0.1cm]{geometry} 
\usepackage{tabularray}
\usepackage{worldflags}
\flagsdefault[width=0.5cm]

\begin{document}

\begin{longtblr}{ colspec = {|X|X|},hlines}
First variable \newline Second variable & \worldflag{FR} \\
First variable & \worldflag{BR} \\
First variable \newline Second variable & \worldflag{CH} \\
\end{longtblr}

\end{document}

enter image description here

2 Answers 2

1

Here, I make the flags slightly larger, and create \Worldflag macro which sets the flag's upper extent to a height of \ht\strutbox above the baseline.

\documentclass{article}
\usepackage[a4paper,margin=0.1cm]{geometry} 
\usepackage{tabularray}
\usepackage{worldflags}
\usepackage{stackengine}
\flagsdefault[width=1.9\baselineskip]
\newcommand\Worldflag[1]{\belowbaseline[-\ht\strutbox]{\worldflag{#1}}}
\begin{document}

\begin{longtblr}{ colspec = {|X|X|},hlines}
First variable \newline Second variable & \Worldflag{FR} \\
First variable & \Worldflag{BR} \\
First variable \newline Second variable & \Worldflag{CH} \\
\end{longtblr}

\end{document}

enter image description here

ADDENDUM

The OP asks how to achieve a similar effect when the flags are made smaller?

Here, I make the flags smaller, add a vertical buffer above and below each flag, via \addstackgap[.6\ht\strutbox]{...} and also adjust the vertical shift of the \belowbaseline. While the particular values can be adjusted, I recommend that the stackgap minus the belowbaseline shift add up to \ht\strutbox.

\documentclass{article}
\usepackage[a4paper,margin=0.1cm]{geometry} 
\usepackage{tabularray}
\usepackage{worldflags}
\usepackage{stackengine}
\flagsdefault[width=1\baselineskip]
\newcommand\Worldflag[1]{\addstackgap[.6\ht\strutbox]{%
  \belowbaseline[-0.4\ht\strutbox]{\worldflag{#1}}}}
\begin{document}

\begin{longtblr}{ colspec = {|X|X|},hlines}
First variable \newline Second variable & \Worldflag{FR} \\
First variable & \Worldflag{BR} \\
First variable \newline Second variable & \Worldflag{CH} \\
\end{longtblr}

\end{document}

enter image description here

4
  • Woww!! Thanks a lot!!! :-) :-)
    – Ommo
    Commented Mar 7 at 17:10
  • Just a small doubt.... In case I make the flags smaller (e.g. \flagsdefault[width=1.2\baselineskip]), how could I vertically center them inside the cells? Indeed, at this moment, the flags are closer to the top lines of the table cells and not vertically centered (you can see it when they are smaller)... :-)
    – Ommo
    Commented Mar 7 at 17:30
  • 1
    @Ommo Please see my ADDENDUM Commented Mar 7 at 17:33
  • Thanks a lot Steven! :-)
    – Ommo
    Commented Mar 7 at 21:10
1

Lower the flag so the height is the same as the height of a strut. Since longtblr adds a small padding, flags won't touch the rules.

\documentclass{article}
\usepackage[a4paper,margin=0.1cm]{geometry}
\usepackage{tabularray}
\usepackage{worldflags}

\flagsdefault[width=0.5cm]
\newcommand{\tflag}[1]{%
  \raisebox{\dimeval{\ht\strutbox-\height}}{\worldflag{#1}}%
}

\begin{document}

\begin{longtblr}{ colspec = {|X|X|},hlines}
First variable \newline Second variable & \tflag{FR} \\
First variable & \tflag{BR} \\
First variable \newline Second variable & \tflag{CH} \\
\end{longtblr}

\end{document}

enter image description here

1
  • A great answer! Thanks a lot @egreg!!
    – Ommo
    Commented Mar 7 at 21:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .