# How to center a line under a figure

I want to put a line to distinguish the graphics from the text in my document. I found a way to add the line but I want it to be at the same length as the caption and not \linewidth. Although, when I set it to a fraction of \linewidth it automatically starts from the left edge and I can't put it exactly under the caption.

Here is my code:

\documentclass{memoir}
\usepackage{lipsum}                 %Needed to create dummy text
\usepackage{graphicx}

\newcommand{\botfigrule}{
\vspace*{5pt}{\hrule height0.8pt width 0.9\linewidth}\vspace{1pt}}

% My caption style
\newcommand{\mycaption}[2][\@empty]{
\captionnamefont{\scshape}
\changecaptionwidth
\captionwidth{0.9\linewidth}
\captiondelim{.\:}
\captionstyle[\centering]{}
\setlength{\belowcaptionskip}{10pt}
\ifx \@empty#1 \caption{#2}\else \caption[#1]{#2}
}

\begin{document}
\lipsum[2]

\begin{figure}[h!]
\centering
\includegraphics[width=0.4\textwidth]{images/example.jpeg}
\mycaption{ \lipsum[1]}
\botfigrule
\label{fig:gr_lattice}
\end{figure}

\lipsum[2]

\end{document}

• Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Max Aug 7 '18 at 13:51
• Traditionally in English typography, captions for figures go below the figure, and this basically would eliminate much of the need for a separator. – Alan Munn Aug 7 '18 at 13:57
• Does \centering not yield the desired result? – Sid Aug 7 '18 at 14:32
• No, sadly \centering does not change anything. – Kwnanan Aug 7 '18 at 14:55

The memoir manual has examples of ruled figures (see p. 173 of the documentation). It suffices to use the following as your \botfigrule command:

\newcommand{\botfigrule}{\rule{.9\linewidth}{0.4pt}\vspace{\onelineskip}}


Here's a full example.

\documentclass{memoir}
\usepackage{lipsum}                 %Needed to create dummy text
\usepackage[draft]{graphicx}

\newcommand{\botfigrule}{\rule{.9\linewidth}{0.4pt}\vspace{\onelineskip}}

% My caption style
\newcommand{\mycaption}[2][\@empty]{
\captionnamefont{\scshape}
\changecaptionwidth
\captionwidth{0.9\linewidth}
\captiondelim{.\:}
\captionstyle[\centering]{}
\setlength{\belowcaptionskip}{10pt}
\ifx \@empty#1 \caption{#2}\else \caption[#1]{#2}
}

\begin{document}
\lipsum[2]

\begin{figure}[h!]
\centering
\includegraphics[width=0.4\textwidth]{images/example.jpeg}
\mycaption{ \lipsum[1]}
\botfigrule
\label{fig:gr_lattice}
\end{figure}

\lipsum[2]

\end{document}


Here is my solution

\documentclass{article}

\newcommand{\botfigrule}{
\vspace*{5pt}{\hrule height0.8pt width \textwidth}\vspace{1pt}}

\usepackage{graphicx}

\begin{document}

\begin{figure}[t]
\centering
\includegraphics[width=\textwidth]{potatoes.jpg}
\caption{ very very very very very very very very very very
very very very very very very very very very very
very very very very very very very very very very
very very very very very very very very very very
long text }
\label{fig:try}
\botfigrule
\end{figure}

\end{document}


I just used \textwidth instead of 0.9\linewidth and a \centering in the figure environment

EDIT:

\documentclass{memoir}
\usepackage{lipsum}                 %Needed to create dummy text
\usepackage{graphicx}

\newcommand{\botfigrule}{
\vspace*{5pt}
\parbox{0.5\textwidth}{
{\hrule height0.8pt width 0.5\textwidth}
}}

% My caption style
\newcommand{\mycaption}[2][\@empty]{
\captionnamefont{\scshape}
\changecaptionwidth
\captionwidth{0.9\linewidth}
\captiondelim{.\:}
\captionstyle[\centering]{}
\setlength{\belowcaptionskip}{10pt}
\ifx \@empty#1 \caption{#2}\else \caption[#1]{#2}
}

\begin{document}
\lipsum[2]

\begin{figure}[h!]
\centering
\includegraphics[width=0.4\textwidth]{potatoes.jpg}
\mycaption{ \lipsum[1]}
\botfigrule
\label{fig:gr_lattice}
\end{figure}

\lipsum[2]

\end{document}

• Thank you but the problem is that I want the line to be smaller than the '\textwidth' and centered below the figure. – Kwnanan Aug 7 '18 at 14:58
• I edited the answer. Now I'm trying to use a \parbox (with a silly width). – Source Aug 7 '18 at 15:10