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

  • 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 Apr 17 '16 at 19:10
  • Thanks, the example was not minimal, I removed the \usepackage{caption}, the problem with horizontal alignment however persists. – Richard Apr 17 '16 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 Apr 17 '16 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 Apr 17 '16 at 19:22
4

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

  • Perfect, even shorter than my initial solution, thank you very much. – Richard Apr 17 '16 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 Apr 17 '16 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.