[Tex/LaTex] How to place a vertical rule between subfigures

rulessubfloats

I have implemeted a figure with subfigures by following the instructions here. Each subfigure is an image and some text beneath it.

I would like to introduce a vertical rule between each subfigure that extends the height of the subfigure, from the top of the image to the bottom of the text.

Here is an example of the code that I have.

\begin{figure*}[ht!]
\begin{subfigure}[t]{0.32\textwidth}
    \includegraphics[width=\textwidth]{tux.png}
    Now that we know who you are, I know who I am. I'm not a mistake!
    It all makes sense!
\end{subfigure}
\rule{1px}{100px}
\begin{subfigure}[t]{0.32\textwidth}
    \includegraphics[width=\textwidth]{tux.png}
    In a comic, you know how you can tell who the arch-villain's going to be?
    He's the exact opposite of the hero. And most times they're friends,
    like you and me!
\end{subfigure}
\rule{1px}{100px}
\begin{subfigure}[t]{0.32\textwidth}
    \includegraphics[width=\textwidth]{tux.png}
    I should've known way back when... You know why, David? Because of the kids.
    They called me Mr Glass.
\end{subfigure}

\begin{subfigure}[t]{0.32\textwidth}
    \includegraphics[width=\textwidth]{tux.png}
    Yeah, I like animals better than people sometimes... Especially dogs.
    Dogs are the best. Every time you come home, they act like they haven't
    seen you in a year.
\end{subfigure}
\rule{1px}{100px}
\begin{subfigure}[t]{0.32\textwidth}
    \includegraphics[width=\textwidth]{tux.png}
    And the good thing about dogs... is they got different dogs for different
    people. Like pit bulls. The dog of dogs. Pit bull can be the right man's
    best friend... or the wrong man's worst enemy.
\end{subfigure}
\rule{1px}{100px}
\begin{subfigure}[t]{0.32\textwidth}
    \includegraphics[width=\textwidth]{tux.png}
    You going to give me a dog for a pet, give me a pit bull. Give me...
    Raoul. Right, Omar? Give me Raoul.
\end{subfigure}
\caption{How can I get vertical rules?}
\end{figure*}

In this code, I have tried to solve the problem by adding \rule{1px}{100px} between each subfigure but the line starts at the bottom of the image, not the text. Also, I don't know how to specify the line height in terms of the subfigures' height.

The line should be the height of the subfigure, including the space occipied by the text beneath it.

The reason why I want to do this is to make the texts easier to read. If the bar extended just between the texts that would be fine.

Best Answer

Don't use px; it doesn't do what you think.

\documentclass{article}
\usepackage{subcaption,graphicx}

\newcommand{\rulesep}{\unskip\ \vrule\ }

\begin{document}
\begin{figure*}[ht!]
\begin{subfigure}[t]{0.32\textwidth}
    \includegraphics[width=\textwidth]{duck}
    Now that we know who you are, I know who I am. I'm not a mistake!
    It all makes sense!
\end{subfigure}
\rulesep
\begin{subfigure}[t]{0.32\textwidth}
    \includegraphics[width=\textwidth]{duck}
    In a comic, you know how you can tell who the arch-villain's going to be?
    He's the exact opposite of the hero. And most times they're friends,
    like you and me!
\end{subfigure}
\rulesep
\begin{subfigure}[t]{0.32\textwidth}
    \includegraphics[width=\textwidth]{duck}
    I should've known way back when... You know why, David? Because of the kids.
    They called me Mr Glass.
\end{subfigure}

\medskip

\begin{subfigure}[t]{0.32\textwidth}
    \includegraphics[width=\textwidth]{duck}
    Yeah, I like animals better than people sometimes... Especially dogs.
    Dogs are the best. Every time you come home, they act like they haven't
    seen you in a year.
\end{subfigure}
\rulesep
\begin{subfigure}[t]{0.32\textwidth}
    \includegraphics[width=\textwidth]{duck}
    And the good thing about dogs... is they got different dogs for different
    people. Like pit bulls. The dog of dogs. Pit bull can be the right man's
    best friend... or the wrong man's worst enemy.
\end{subfigure}
\rulesep
\begin{subfigure}[t]{0.32\textwidth}
    \includegraphics[width=\textwidth]{duck}
    You going to give me a dog for a pet, give me a pit bull. Give me...
    Raoul. Right, Omar? Give me Raoul.
\end{subfigure}
\caption{How can I get vertical rules?}
\end{figure*}
\end{document}

enter image description here

If you change the definition of \rulesep into

\newcommand{\rulesep}{\unskip\ \vrule height -1ex\ }

you get the following:

enter image description here

The key is using \begin{subcaption}[t] and that the pictures on a row all have the same height. The reference point of the subfigures is at the bottom of the picture, and \vrule fills top to bottom, but if we fix a height it will only fill down to the bottom; since the height is negative, the filling starts 1ex below the baseline (where the reference points are placed).

Related Question