Graphics, Figures & TablesOverlapping captions

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Carbonado
Posts: 2
Joined: Sat Jul 01, 2017 10:49 pm

Overlapping captions

Post by Carbonado »

Hello, I'm having a problem with the captions on putting two figures side by side. Basically, they just won't stay in their own columns.
cols.png
cols.png (211.66 KiB) Viewed 7179 times
Here's my code.

Code: Select all

\begin{figure}
\centering
\begin{minipage}{.5\textwidth}
  \centering
  \includegraphics[width=.9\linewidth]{Fig-6-A}
  \captionof{figure}[TEM]{Image does its thing but it does barely.}
  \label{Fig6a}
\end{minipage}%
\hfill
\begin{minipage}{.5\textwidth}
  \centering
  \includegraphics[width=.9\linewidth]{Fig-6-B}
  \captionof{figure}[TEM2]{Text2 which extends for multiple lines and apparently glitches when I do stuff because of reasons I barely understand}
  \label{Fig6b}
\end{minipage}
\end{figure}
Anyone can tell me what's wrong?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
TikZ book
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Overlapping captions

Post by Johannes_B »

Can you provide a minimal working example so we can exactly reproduce your issue?
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10314
Joined: Mon Mar 10, 2008 9:44 pm

Overlapping captions

Post by Stefan Kottwitz »

Hi Carbonado,

welcome to the forum!

The text in the minipages would not overlap. You are not posting your original code, since the text is different, and the code sample you posted doesn't show that issue, there's no overlapping.

Nobody can test that code without extending it. You could avoid that each reader has to work to complete it by posting a Infominimal working example that we could test immediately. And that shows the issue.

This, with your code, has no overlapping, click on "Open in Overleaf" to see it:

Code: Select all

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{capt-of}
\begin{document}
\begin{figure}
\centering
\begin{minipage}{.5\textwidth}
  \centering
  \includegraphics[width=.9\linewidth]{Fig-6-A}
  \captionof{figure}[TEM]{Image does its thing but it does barely.}
  \label{Fig6a}
\end{minipage}%
\hfill
\begin{minipage}{.5\textwidth}
  \centering
  \includegraphics[width=.9\linewidth]{Fig-6-B}
  \captionof{figure}[TEM2]{Text2 which extends for multiple lines
     and apparently glitches when I do stuff because of reasons
     I barely understand}
  \label{Fig6b}
\end{minipage}
\end{figure}
\end{document}
Now, can you post your code, that shows overlapping? Reduced as much as possible, but compilable.

With 2 minipages and each having a width of .5\textwidth, they touch each other of course, and so the captions are touching. I would make them a bit smaller to have some space in-between with the \hfill.

Stefan
LaTeX.org admin
Carbonado
Posts: 2
Joined: Sat Jul 01, 2017 10:49 pm

Overlapping captions

Post by Carbonado »

I... see.

After failing to make it compile while trying to make a minimal working example, I noticed I was using a special document class provided by my work institution (it's kinda big, too, so... no copying it). And reading its contents to try and strip it down to something that would compile, noticed that captions were set to a fixed value! That explains why they were spilling all over the place.

Here's the offender. I can't believe I had to look under the hood for this, going all the way to the .cls file...
\captionsetup{width=0.95\textwidth,textfont=footnotesize,labelfont={bf,small}}
When I remove the width constraint, it stops doing that.


Sorry to bug you, I should've been able to figure that one out myself. See you around!
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Overlapping captions

Post by Johannes_B »

Glad to hear your issue is resolved :-)
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply