类似如下: 如何在图像之间设置彩色虚线垂直规则
我想在两个子图之间放置一条虚线。我可以使用 \vrule 来实现,但是我对虚线所做的任何操作都会停止在图形底部,而不是延伸到子标题。我在图形中使用 subcaption 包。
以下是目前的代码:
\documentclass{article}
\usepackage{subcaption,graphicx}
\usepackage{tikz}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[multidot]{grffile}
\usepackage{calc}
\begin{document}
\begin{figure}
\centering
\subcaptionbox{This is the first subcaption
\label{fig:solid1}}
{\includegraphics[width=0.2\textwidth]{example-image-a}}
\hspace{2pt}
\unskip\vrule
\hspace{2pt}
\subcaptionbox{Get your second subcaptions here
\label{fig:solid2}}
{\includegraphics[width=0.2\textwidth]{example-image-a}}
\caption{This separator has the right height, but isn't dashed.}
\label{fig:solid}
\end{figure}
\begin{figure}
\centering
\def\testBox{\subcaptionbox{This is the first subcaption
\label{fig:dash1}}
{\includegraphics[width=0.2\textwidth]{example-image-b}}}
\newlength\figHeight
\setlength\figHeight{\heightof{\testBox}}
\testBox
\hspace{3pt}
\tikz{\draw[densely dashed, thick](0,\figHeight) -- (0,0);}
\hspace{1pt}
\subcaptionbox{Get your second subcaptions here
\label{fig:dash2}}
{\includegraphics[width=0.2\textwidth]{example-image-b}}
\caption{This separator is dashed, but is too short.}
\label{fig:dashes}
\end{figure}
\end{document}
答案1
使用nicematrix
包将封装成subtitle boxes
表格形式,然后使用\Block
命令绘制虚线规则。
\Block[borders={right,tikz=dashed}]{1-1}{}
将仅在第一个节点的右侧绘制虚线规则。
需要加载 Tikz 包。我会编译两次。
\documentclass{article}
\usepackage{subcaption,graphicx}
\usepackage{tikz}%<<<<<<<<<<<<<<
\usepackage{nicematrix}%<<<<<<<<<<<<<<
\begin{document}
\begin{figure}
\centering
\begin{NiceTabular}{cc}
\Block[borders={right,tikz={densely dashed, thick}}]{1-1}{}%draw the dashed rule only on the right side of the first node
\subcaptionbox{This is the first subcaption \label{fig:solid1}} {\includegraphics[width=0.25\linewidth]{example-image-b}}&
\subcaptionbox{Get your second subcaptions here \label{fig:solid2}}{\includegraphics[width=0.25\linewidth]{example-image-b}}
\end{NiceTabular}
\end{figure}
\end{document}
答案2
您可以使用arydshln
\documentclass{article}
\usepackage{subcaption,graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{arydshln}
\begin{document}
\begin{figure}[htp]
\centering
\begin{tabular}{@{} c : c @{}}
\subcaptionbox{This is the first subcaption\label{fig:solid1}}
{\includegraphics[width=0.2\textwidth]{example-image-a}}
&
\subcaptionbox{Get your second subcaptions here\label{fig:solid2}}
{\includegraphics[width=0.2\textwidth]{example-image-a}}
\end{tabular}
\caption{This separator has the right height, but isn't dashed.}
\label{fig:solid}
\end{figure}
\end{document}
但我看不出这如何改善排版。