1

After following the code for the solution of this question I am struggling to get the second line of the captions to stay centered. Normally the first line of text is always centered but once there are two or more lines the text switches to the "justified" alignment (block text). I have tried putting both \begin{center} and \centering within the minipage but neither do anything to the captions, nor do they produce any errors.

Here's my code. Although I checked all the packages and commands and don't think they interfere but I'll add them just in case anyone notices a problem.

\documentclass{article}
\usepackage[margin=0.75in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{multicol}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage{gensymb}
\usepackage{float}
\usepackage{biblatex}
\usepackage{mwe}
\usepackage{natbib}
\usepackage{graphicx}

\renewcommand\thesection{\Alph{section}}
\newcommand{\HRule}[1]{\rule{\linewidth}{#1}}

\begin{document}

\begin{figure}[H]
\centering
\begin{minipage}{0.45\textwidth}
    \centering
    \includegraphics[width=\textwidth]{log-hhcf.png}
    \caption{Logarithmic graph for HHCF gold sample.}
    \label{log-hhcf}
\end{minipage}\hfill
\begin{minipage}{0.45\textwidth}
    \centering
    \includegraphics[width=\textwidth]{hhcf.png}
    \caption{HHCF for gold sample with all the relevant fitted lines and functions.}
    \label{hhcf}
\end{minipage}
\end{figure}

\end{document}

I get this:

two figures side by side

Anyone know another way to center the text of the captions on my figures?

  • 1
    Welcome to TeX SX! You should take a look at the floatrow package. – Bernard Jun 2 '19 at 16:26
  • 2
    the captions are the full width of your minipages, it is just that the images look further to the right as you see the rectangle of the main axes, but their width includes the rotated text at the left – David Carlisle Jun 2 '19 at 16:29
  • Welcome to TeX.SX! @NiamhO'SS ... If you mean you want the captions to be aligned (to start from the same height) make it clear because in other case the above comment of David is the answer to your problem... If you want them aligned, you could add the captions inside minipages under the minipages of the figures and both pairs of minipages inside \textwidth container minipages ... or similar... – koleygr Jun 2 '19 at 16:41
  • I would like the text of the captions to be centered within the minipage (not necessarily centered with respect to the image, just centered text). Specifically because it doesn't look good when text goes to the next line. – Niamh O'SS Jun 2 '19 at 17:37
  • I voted to reopen the question because after the last comment of the OP seems that (s)he needs the captions center aligned one with the other and not a centered caption below the figure. (OP's English just seems not good enough to express that request) – koleygr Jun 4 '19 at 20:25
1

It is not very clear, how you like to have formatted your captions, hence two guessing:

enter image description here

\documentclass{article}
\usepackage[margin=0.75in]{geometry}
\usepackage{graphicx}
\usepackage{caption}

\begin{document}

\textbf{first example}:
\begin{figure}[htb]
\captionsetup{justification=centering}
\begin{minipage}[t]{0.45\textwidth}
    \includegraphics[width=\textwidth]{example-image-duck}
    \caption{Logarithmic graph for HHCF gold sample.}
    \label{log-hhcf}
\end{minipage}\hfill
\begin{minipage}[t]{0.45\textwidth}
    \includegraphics[width=\textwidth]{example-image-duck}
    \caption{HHCF for gold sample with all the relevant fitted lines and functions.}
    \label{hhcf}
\end{minipage}
\end{figure}

\textbf{second example}:
\begin{figure}[htb]
\captionsetup{justification=centerlast}
\begin{minipage}[t]{0.45\textwidth}
    \includegraphics[width=\textwidth]{example-image-duck}
    \caption{Logarithmic graph for HHCF gold sample.}
    \label{log-hhcf}
\end{minipage}\hfill
\begin{minipage}[t]{0.45\textwidth}
    \includegraphics[width=\textwidth]{example-image-duck}
    \caption{HHCF for gold sample with all the relevant fitted lines and functions.}
    \label{hhcf}
\end{minipage}
\end{figure}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.