2

Similar to this: How to set color dashed vertical rule between images

I want to place a dashed line between two subfigures. I have been able to get it working with a \vrule, but anything I do with the dashed lines stops at the base of the figures rather than extending through the subcaptions. I am using the subcaption package for the figures.

Here is the code so far:

\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{\drawdensely dashed, thick -- (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}

Also, why do I need to have different \hspace distances to center the dashed line? figure 1 result

figure 2 result

egreg
  • 1,121,712
Popyd10
  • 23

2 Answers2

2

Use the nicematrix package to encapsulate the subtitle boxes in tabular form, and then use the \Block command to draw the dashed rule.

\Block[borders={right,tikz=dashed}]{1-1}{} will draw the dashed rule only on the right side of the first node.

Requires the Tikz package to be loaded. I will compile it twice.

C

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

Simon Dispa
  • 39,141
0

You can use 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}

I can't see how this improves the typesetting, though.

enter image description here

egreg
  • 1,121,712