3

I'm writing a LaTeX document where I want two or three QR codes vertically aligned with caption on each. Unfortunately the first QR code is always one line lower than the other QR codes and I can't figure out why.

I have a workaround with negative \vspace, but I'm hoping to find the error or something neater.

MWE

\documentclass[12pt,a5paper]{book}
\usepackage[]{qrcode}
\usepackage{subcaption}
\begin{document}

\begin{figure}[ht]
    \centering
    \begin{subfigure}[t]{0.2\textwidth}    
        \centering        
        \qrcode[]{Text1}
       \caption*{Text1}
    \end{subfigure}
        \qquad
    \begin{subfigure}[ht]{0.2\textwidth}
        \centering    
        \qrcode[]{Text2}
        \caption*{Text2}
    \end{subfigure}      

\end{figure}
\end{document}

enter image description here

4
  • Welcome to TeX.SX! Thank you for your example. You don't need to load caption when you use subcaption. Latter one does \RequirePackage{caption}.
    – Ruben
    Commented Apr 17, 2016 at 19:10
  • Thanks, the example was not minimal, I removed the \usepackage{caption}, the problem with horizontal alignment however persists.
    – Richard
    Commented Apr 17, 2016 at 19:14
  • Sure, dont worry. Your example was totally fine. Just a fineness on the use of the caption package bundle I was pointing to... I posted an answer that solves the issue.
    – Ruben
    Commented Apr 17, 2016 at 19:17
  • @Richard I removed the [solved] part of the title, as the way we mark questions solved on this site is to accept answers. See this question for how to do it.
    – sodd
    Commented Apr 17, 2016 at 19:22

1 Answer 1

5

You can use \subcaptionboxes as they get vertically aligned automatically:

\documentclass[12pt,a5paper]{article}
\usepackage{qrcode}
\usepackage{subcaption}

\begin{document}
\begin{figure}[ht]
  \centering
  \subcaptionbox{Text1}{\qrcode{Text1}}
  \qquad
  \subcaptionbox{Text2}{\qrcode{Text2}}   
\end{figure}
\end{document}

output_crop

2
  • Perfect, even shorter than my initial solution, thank you very much.
    – Richard
    Commented Apr 17, 2016 at 19:16
  • 1
    @Richard, the usual way to say thanks is to upvote and accept the answer (of course the one which helped most :)
    – Ruben
    Commented Apr 17, 2016 at 19:20

You must log in to answer this question.

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