# Fit decoRule to picture lentgh

I am using decoRule to draw a line under my figure and before the caption. I would like to have this line with the same lenght of my picture.

the code I am using is the following:

 \begin{figure}
\begin{subfigure}[b]{0.6\textwidth}
\includegraphics[width=\textwidth]{stereolithography}
\label{fig:sla}
\end{subfigure}
%
\begin{subfigure}[b]{0.6\textwidth}
\includegraphics[width=\textwidth]{dlp1}
\label{fig:dlp}
\end{subfigure}
\decoRule
\caption[Schematic of Vat Photopolymerization.]{a) Schematic of top-cured laser based machine, Stereolithography. b) Schematic of bottom-cured Digital Light Processing (DLP) machine. Courtesy of 3D Printing Industry \parencite{3d_printing_industry_2016}.}
\end{figure}

• Just change the definition of \decoRule to take an optional argument for the line length and use \decoRule[\textwidth]. For more concrete help, extend the snippet to a minimal working example (MWE), which would show, how/where \decoRule is defined. – Heiko Oberdiek Sep 25 '16 at 10:29
• @HeikoOberdiek sorry for the late reply. Here is how I defined DecoRule \newcommand{\decoRule}{\rule{\textwidth}{.4pt}} Is it possible to tell somehow that the length should be the same as the figure in which I am using it? – Alexis Charalambis Sep 26 '16 at 12:59
• It should be the width, that is used as option for \includegraphics. Make a MWE, which show, how/where subfigure is defined. Also the specified length values do not look correct. The outer environment subfigure uses .6\textwidth, but the image is included with width=\textwidth. – Heiko Oberdiek Sep 26 '16 at 16:55
• @HeikoOberdiek Not to mention .6\textwidth + space + .6\textwidth fitting inside \texwidth ... – cfr Sep 27 '16 at 3:03

As it stands, your question is unanswerable since none but you know how \decoRule is defined.

There is a \decorule defined by the decorule package. However, it looks nothing like the rule in your image, so presumably it isn't that. In fact, the rule in your image looks like a bog-standard rule.

If so, then you can just set \vrule to the appropriate width - for one example.

The main issue is that your code will give bad boxes because you cannot fit 120% of the \textwidth plus an additional space into a \textwidth text block and expect things to work nicely.

The following uses chngpage to adjust the left and right margins for the image and rule, reverting to the standard settings for the caption. This eliminates bad boxes.

Obviously, I changed the images. I'm sure you'll agree these are a considerable improvement. A pedant might quibble over the relevance of the caption and the transformation of the citation into a question mark. However, sometimes you just have to take your cats where you can find them and damn the critics.

\documentclass{article}
\usepackage{graphicx,subcaption,chngpage,calc}
\newlength\fulltextwidth
\setlength\fulltextwidth{\textwidth}
\newlength\fullpicwidth
\setlength\fullpicwidth{1.2\textwidth+2\fboxsep+2\fboxrule}
\begin{document}
\begin{figure}
\fbox{%
\begin{subfigure}[b]{0.6\fulltextwidth}
\includegraphics[width=\textwidth]{cauldron}
\label{fig:sla}
\end{subfigure}%
\begin{subfigure}[b]{0.6\fulltextwidth}
\includegraphics[width=\textwidth]{cathod}
\label{fig:dlp}
\end{subfigure}%
}
\par
\vrule height 1pt depth 1pt width \fullpicwidth
\par
\caption[Schematic of Vat Photopolymerization.]{a) Schematic of top-cured laser based machine, Stereolithography. b) Schematic of bottom-cured Digital Light Processing (DLP) machine. Courtesy of 3D Printing Industry \cite{3d_printing_industry_2016}.}
\end{figure}
\end{document}


• decoRule is defined as following: \newcommand{\decoRule}{\rule{\textwidth}{.4pt}} Is there a way to have the lenght of this line as the same of the figure I am using? – Alexis Charalambis Sep 26 '16 at 12:54
• You mean height .2pt depth .2pt rather than height 1pt depth 1pt? You can make the dimensions whatever you like. – cfr Sep 26 '16 at 16:11
• @AlexisCharalambis Note that the example I gave shows you how to make the rule match the width of the figure. I'm not really certain what you're asking. You must surely be getting complaints about bad boxes with your code. These are telling you stuff isn't fitting together properly - you can't expect the results to fit nicely in this case! – cfr Sep 27 '16 at 3:05

You could center the horizontal line by using \centering. You also need to leave an empty line before placing the \centering command for it to not center all of your subfigures. So your code should look like this.

\begin{figure}
\begin{subfigure}[b]{0.6\textwidth}
\includegraphics[width=\textwidth]{stereolithography}
\label{fig:sla}
\end{subfigure}
%
\begin{subfigure}[b]{0.6\textwidth}
\includegraphics[width=\textwidth]{dlp1}
\label{fig:dlp}
\end{subfigure}