7

I'm trying to create a table with three columns, that in the first column it depict a country banner. I'm using the the worldflags package to do it, but when I use it inside the longtable package it gets misaligned. Can you help me?

\documentclass[a4paper, 12pt]{article}
\usepackage{graphicx}
\usepackage{worldflags}
\usepackage{tikz}
\usepackage{longtable}

\begin{document}

\section{Total patentes 2024}

\begin{longtable}[c]{|l|c|r|} 
\hline
País & Código & Patentes\\ \hline

\begin{tikzpicture}
    \worldflag[length=22.5mm]{AE}
\end{tikzpicture}&
Arabia Saudita (AE) & 1 \\ \hline
\begin{tikzpicture}
\worldflag[length=22.5mm]{AR}
\end{tikzpicture} &
Argentina (AR) &  459\\ \hline
\begin{tikzpicture}
\worldflag[length=22.5mm]{AT}
\end{tikzpicture} &
 Austria (AT) &  12\\ \hline
\begin{tikzpicture}
\worldflag[length=22.5mm]{AU}
\end{tikzpicture} &
Australia (AU) &  31\\ \hline

\end{longtable}
\end{document}

When I compile it this is the outcome:

This is the outcome I get by using that code

1
  • 1
    The first flag is of the United Arab Emirates, not of Saudi Arabia.
    – egreg
    Commented Aug 5 at 12:50

2 Answers 2

11

The \worldflag macro creates a whole tikzpicture. It is generally not a good idea to nest tikzpictures, so remove the additional tikzpicture around it:

\documentclass[a4paper, 12pt]{article}
\usepackage{graphicx}
\usepackage{worldflags}
\usepackage{tikz}
\usepackage{longtable}

\begin{document}

\section{Total patentes 2024}

\begin{longtable}[c]{|l|c|r|} 
\hline
País & Código & Patentes\\ \hline
    \worldflag[length=22.5mm]{UNO}
&
United Nations (UNO) & \\ \hline
\end{longtable}
\end{document}

enter image description here

If you prefer to use a tikzpicture, you could add the flag as a \pic:

\documentclass[a4paper, 12pt]{article}
\usepackage{graphicx}
\usepackage{worldflags}
\usepackage{tikz}
\usepackage{longtable}


\begin{document}

\section{Total patentes 2024}

\begin{longtable}[c]{|l|c|r|} 
\hline
País & Código & Patentes\\ \hline
    \begin{tikzpicture}[baseline]
      \pic[country=UNO] at (0,0) {worldflag};
    \end{tikzpicture}
&
United Nations (UNO) & \\ \hline
\end{longtable}
\end{document}

enter image description here

5
  • Thanks everyone!! Commented Aug 4 at 21:55
  • but you are clearly missing the most important flag. Commented Aug 4 at 22:11
  • @DavidCarlisle I can add Germany, no problem :) Commented Aug 4 at 22:13
  • I was following the International Code,(DE) the countries are not in alphabetical order (in spanish Alemania will be appear higher) Commented Aug 5 at 0:43
  • 2
    @PabloPiccoPlencovich you may ignore us, SamCarter is German and I am British we are just teasing each other out of habit. Commented Aug 5 at 10:50
6

You can't nest tikzpictures. Anyway, you should also fix the height and a spurious space introduced by the worldflag package.

\documentclass[a4paper, 12pt]{article}
\usepackage{graphicx}
\usepackage{worldflags}
\usepackage{longtable}

\newcommand{\flag}[1]{%
  \sbox0{\worldflag[length=22.5mm]{#1}\unskip}% \unskip fixes the spurious space
  \rule{0pt}{\dimeval{\ht0+\dp\strutbox}}%
  \usebox{0}%
}

\begin{document}

\section{Total patentes 2024}

\begin{longtable}[c]{|l|c|r|}
\hline País & Código & Patentes\\ \hline \endhead

\flag{AE} & Emiratos Árabes Unidos & 1 \\ \hline
\flag{AR} & Argentina (AR) &  459\\ \hline
\flag{AT} & Austria (AT) &  12\\ \hline
\flag{AU} & Australia (AU) &  31\\ \hline
\end{longtable}

\end{document}

output

The spurious space is at line 323 of worldflags.sty, that should be

\end{tikzpicture}}{\relax}%

and unfortunately it misses the %.

With a more open look:

\documentclass[a4paper, 12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}
\usepackage{worldflags}
\usepackage{longtable}
\usepackage{booktabs}

\newcommand{\flag}[1]{\worldflag[length=22.5mm]{#1}\unskip}

\begin{document}

\section{Total patentes 2024}

\begin{longtable}{@{}lcr@{}} 
\toprule País & Código & Patentes\\ \midrule \endhead
\midrule \multicolumn{3}{@{}r@{}}{\itshape Continúa en la página siguiente} \endfoot
\bottomrule \endlastfoot

\flag{AE} & Emiratos Árabes Unidos & 1 \\
\flag{AR} & Argentina (AR) &  459\\
\flag{AT} & Austria (AT) &  12\\
\flag{AU} & Australia (AU) &  31\\

\flag{AE} & Emiratos Árabes Unidos & 1 \\
\flag{AR} & Argentina (AR) &  459\\
\flag{AT} & Austria (AT) &  12\\
\flag{AU} & Australia (AU) &  31\\

\flag{AE} & Emiratos Árabes Unidos & 1 \\
\flag{AR} & Argentina (AR) &  459\\
\flag{AT} & Austria (AT) &  12\\
\flag{AU} & Australia (AU) &  31\\

\flag{AE} & Emiratos Árabes Unidos & 1 \\
\flag{AR} & Argentina (AR) &  459\\
\flag{AT} & Austria (AT) &  12\\
\flag{AU} & Australia (AU) &  31\\
\end{longtable}

\end{document}

open look

You must log in to answer this question.

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