# How can I place a vertical rule between subfigures?

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.

• I’d rather use a larger distance between texts for the same reasons you shouldn’t put vertical lines in tables, cf. booktabs documentation. Feb 8 '14 at 13:01
• I'm tempted to agree with you on that one on the grounds that I think it looks better. Feb 8 '14 at 19:12

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}


If you change the definition of \rulesep into

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


you get the following:

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).

• Yes that gives what I asked for, great. Must admit though, doesn't look as good as I'd hoped. Would it be possible to limit the rule just to the text bit (i.e. not between the pictures)? Just interested to see what it's like but I think increasing the spacing like Crissov commented might be the way to go. Feb 8 '14 at 19:07
• @starfry You can change \vrule into \vrule height -1ex in the definition of \rulesep. So long as the pictures have the same height, this should work. Feb 8 '14 at 20:18
• Yes, that does it. Latex is a dark art indeed. Feb 8 '14 at 21:01
• @starfry The key is that you're using \begin{subcaption}[t], so the reference point of those boxes is the bottom of the picture, which is the object at the top. With \vrule we tell TeX to draw a rule filling the line from top to bottom; if we set its height to be slightly negative, it will only fill to the bottom. Feb 8 '14 at 21:07