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 02 '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 02 '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 02 '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 02 '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 04 '19 at 20:25
  • @koleygr the answer to the question this was duplicate to answered my question. I did actually need a centered caption below the figure. – Niamh O'SS Jun 05 '19 at 07:41
  • @NiamhO'SS ... Please find the "button" "close" below your question and press it to ask from the community to be closed as a duplicate of the answer here: https://tex.stackexchange.com/questions/95207/how-to-center-a-specific-caption. Sorry for the confusion but my English are not good enough too and I understood wrong ... You could accept the answer of Zarko till then until I will delete mine. Thanks for informing. Happy TeXing! – koleygr Jun 05 '19 at 12:40
  • Unfortunately I already flagged it as a duplicate, so I cannot do so again. – Niamh O'SS Jun 14 '19 at 19:24

1 Answers1

2

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}
Zarko
  • 296,517