如何在子图之间放置垂直线?

如何在子图之间放置垂直线?

我按照说明实现了一个带有子图的图形这里。每个子图都是一张图片和其下方的一些文本。

我想在每个子图之间引入一条垂直规则,延伸子图的高度,从图像的顶部到文本的底部。

这是我所拥有的代码示例。

\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*}

在此代码中,我尝试通过在\rule{1px}{100px}每个子图之间添加来解决问题,但线条从图像底部开始,而不是文本。另外,我不知道如何根据子图的高度指定线条高度。

该线应为子图的高度,包括其下方文本占据的空间。

我之所以要这样做,是为了让文本更容易阅读。如果栏正好延伸到文本之间,那就没问题了。

答案1

不要使用px;它不会达到您所想的效果。

\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

\rulesep如果你把的定义改为

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

您将获得以下内容:

enter image description here

关键是使用\begin{subcaption}[t]并且一行中的图片都具有相同的高度。子图的参考点位于图片的底部,并\vrule从上到下填充,但如果我们固定高度,它只会填充到底部;由于高度为负数,因此填充从基线(参考点所在的位置)下方 1ex 开始。

相关内容