# How to properly align picture, text and QR-code vertically and horizontally?

Similar to this earlier question of mine, but this time: +a QR code, -itemize

Ideally, the picture, the text and the QR code should be vertically top-aligned; the text should horizontally stick to the image, and the QR code to the right margin.

This is what I've managed so far, partially employing the tips from the abovementioned earlier question: In the first attempt, the image and the text are well aligned, but the QR code not, neither vertically nor horizontally. In the second attempt, the image and the QR code are vertically aligned, but the text not, and again the QR code produces an Overfull \hbox .

\documentclass[a4paper, 10pt]{scrartcl}

\usepackage[american]{babel}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[a4paper, left=12.7mm, right=12.7mm, top=12.7mm, bottom=13mm]{geometry}
\usepackage{showframe}

\usepackage{tabu, booktabs}
\usepackage{graphicx}
\usepackage{qrcode}
\newlength\threeLines
\setlength{\threeLines}{12mm}

\begin{document}

\sffamily
\tabulinesep=0pt
\extrarowsep=0pt
\begin{tabu}{@{} X[l,1] X[l,18] X[r,1] @{}}
\includegraphics[width=\threeLines, height=\threeLines, valign=t]{example-image} &
{This text spans \par
Over Three Lines and \par
Should be close to the image} &
\qrcode[height=\threeLines]{https://tex.stackexchange.com/questions/289863/how-to-get-rid-of-vertical-offset-in-a-table-containing-pictures} \\
\end{tabu}

\vspace*{24pt}

\begin{tabu}{@{} X[l,1] X[l,18] X[r,1] @{}}
\toprule
\raisebox{-\height}[0pt][1.1\height]{\includegraphics[width=\threeLines, height=\threeLines, valign=t]{example-image}} &
{This text spans \par
Over Three Lines and \par
Should be close to the image} &
\raisebox{-\height}[0pt][1.1\height]{\qrcode[height=\threeLines]{https://tex.stackexchange.com/questions/289863/how-to-get-rid-of-vertical-offset-in-a-table-containing-pictures}} \\
\end{tabu}

\end{document}


It also seems very clumsy to me to manually set the column width ration to 18, but otherwise the horizontal distance between image and text grows too big.

So my question is: How to properly align the three elements? Something better than tabu(lar)? I would like to avoid TikZ if possible.

• You could use parboxes with the last \hfilled to be right-aligned. Feb 10, 2017 at 15:03
• Like this? \includegraphics[width=\threeLines, height=\threeLines]{example-image} \parbox[l]{60mm}{This text spans \par Over Three Lines and \par Should be close to the image} \hfill \qrcode... This fixes the horizontal alignment of the QR code, but not the vertical alignment. It's still messed up, with or without the valign=t option in \includegraphics. Feb 10, 2017 at 15:10
• I thought about something like that, maybe in combination with adjustbox, but I had to test it to say something specific. Feb 10, 2017 at 15:12

You could use a solution based on a combination of \parbox and \adjustbox which would better up the vertical alignment.

\documentclass[a4paper, 10pt]{scrartcl}
\usepackage[american]{babel}
\usepackage{lmodern}
\usepackage[a4paper, left=12.7mm, right=12.7mm, top=12.7mm, bottom=13mm]{geometry}
\usepackage{showframe}

\usepackage{graphicx}
\usepackage{qrcode}
\newlength\threeLines
\setlength{\threeLines}{12mm}

\begin{document}

\noindent
\includegraphics[width=\threeLines, height=\threeLines, valign=t]{example-image}%
Over Three Lines and\\
Should be close to the image}}\hfill

\vspace*{24pt}\hrule\vspace*{5pt}

\noindent
\includegraphics[width=\threeLines, height=\threeLines, valign=t]{example-image}%
Over Three Lines and\\
Should be close to the image}}\hfill
\end{document}

• Actually, it works better for me without the \adjustbox around the text. Thus, the text is slightly better aligned to the top. Thanks to you great people here on Stackexchange, I could resolve this one. However, it still bothers me that such "simple" things in (La)TeX require such advanced knowledge. How is a complete beginner supposed to get this done? Why doesn't \includegraphics[width=\threeLines, height=\threeLines]{example-image} {This text spans\\ Over Three Lines and\\ Should be close to the image}\hfill \qrcode[height=\threeLines]{...} do the job OOTB? Feb 22, 2017 at 10:36
• @rotton The adjustboxes are just a fallback to ensure the correct alignment in case LaTeX's automatism (which is usually great) does something strange. And the point of why it doesn't work is simple, the purpose of LaTeX was not to design those special cases but to provide an interface to the great world of TeX, specialized on typesetting (books and scientific publications at first place). So usually you are expected to know the basics for publishing, but design is another level (further into TeX). For example your \threeLines could also be more exact as 3\baselineskip to span three lines. Feb 22, 2017 at 10:43

The table doesn't seem to be doing much here so I removed it.

\documentclass[a4paper, 10pt]{scrartcl}

\usepackage[american]{babel}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[a4paper, left=12.7mm, right=12.7mm, top=12.7mm, bottom=13mm]{geometry}
\usepackage{showframe}

\usepackage{tabu, booktabs}
\usepackage{graphicx}
\usepackage{qrcode}
\newlength\threeLines
\setlength{\threeLines}{12mm}

\begin{document}

\sffamily

\noindent
\includegraphics[width=\threeLines, height=\threeLines]{example-image}%
\parbox[b]{5cm}{This text spans\\
Over Three Lines and\\
Should be close to the image}\hfill
\raisebox{\depth}{\qrcode[height=\threeLines,tight]{http://tex.stackexchange.com/questions/289863/how-to-get-rid-of-vertical-offset-in-a-table-containing-pictures}}

\vspace*{24pt}

\hrule

\vspace*{5pt}

\noindent
\includegraphics[width=\threeLines, height=\threeLines]{example-image}%
\parbox[b]{5cm}{This text spans\\
Over Three Lines and\\
Should be close to the image}\hfill
\raisebox{\depth}{\qrcode[height=\threeLines]{http://tex.stackexchange.com/questions/289863/how-to-get-rid-of-vertical-offset-in-a-table-containing-pictures}}

\end{document}

• Your solution has just one drawback: The OP wanted also a vertically corrected alignment of the qrcode. Feb 10, 2017 at 15:20
• @TeXnician oh perhaps so did OP want them all on the baseline, perhaps I'l remove those two t as teh default would be baseline aligned... Feb 10, 2017 at 15:24
• @TeXnician better? Feb 10, 2017 at 15:30
• Of course, much better ;) Feb 10, 2017 at 15:31

and "pure" tabu solution (with use correct tabu syntax):

\documentclass[a4paper, 10pt]{scrartcl}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[a4paper, left=12.7mm, right=12.7mm, top=12.7mm, bottom=13mm]{geometry}

\usepackage{booktabs, tabu}
\usepackage{graphicx}
\usepackage{qrcode}
\newlength\threeLines
\setlength{\threeLines}{12mm}

\usepackage{showframe}
\renewcommand*\ShowFrameColor{\color{red}}

\begin{document}

\sffamily
\centering%
\setlength\tabcolsep{2pt}
\begin{tabu} to \linewidth {@{} m{\threeLines}   X[l, m] m{\threeLines}  @{}}
\includegraphics[width=\threeLines, height=\threeLines]{example-image}
&
This text spans \par
Over Three Lines and \par
Should be close to the image
&
\qrcode[height=\threeLines]{http://tex.stackexchange.com/questions/289863/how-to-get-rid-of-vertical-offset-in-a-table-containing-pictures}
\end{tabu}

\vspace*{24pt}

\begin{tabu} to \linewidth {@{} m{\threeLines}   X[l, m] m{\threeLines}  @{}}
\toprule
\includegraphics[width=\threeLines, height=\threeLines]{example-image}
&
This text spans \par
Over Three Lines and \par
Should be close to the image
&
\qrcode[height=\threeLines]{http://tex.stackexchange.com/questions/289863/how-to-get-rid-of-vertical-offset-in-a-table-containing-pictures}
\end{tabu}
\end{document}