0

I'm using the LaTeX Thesis Template by Matthias Pospiech and regardless of what I try - captionbeside, minipages, etc. -, LaTeX always places the caption below the figure. But I want them beside the figure for some figures.

I failed to reproduce the issue with a MWE. Does anyone has a guess what might be the cause? I'm getting nuts. It still persists if I comment all settings related to floatrow and caption.

Some examples

Plain:

\begin{figure}
    \includegraphics[width=.6\textwidth]{example-image-a}
    \caption{Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante. Donec ullamcorper, felis non sodales commodo, lectus velit ultrices augue, a dignissim nibh lectus placerat pede. Vivamus nunc nunc, molestie ut, ultricies vel, semper in, velit.}
\end{figure}

plain

\begin{figure}
    \begin{captionbeside}{Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante. Donec ullamcorper, felis non sodales commodo, lectus velit ultrices augue, a dignissim nibh lectus placerat pede. Vivamus nunc nunc, molestie ut, ultricies vel, semper in, velit.}[o]
        \includegraphics[width=.6\textwidth]{example-image-a}
    \end{captionbeside}
\end{figure}

captionbeside

\begin{figure}
    \begin{minipage}[t]{0.6\textwidth}
        \mbox{}\\[-\baselineskip]
        \includegraphics[width=\textwidth]{example-image-a}
    \end{minipage}~\hfill~%
    \begin{minipage}[t]{0.38\textwidth}
        \mbox{}\\[-\baselineskip]
        \caption{Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante. Donec ullamcorper, felis non sodales commodo, lectus velit ultrices augue, a dignissim nibh lectus placerat pede. Vivamus nunc nunc, molestie ut, ultricies vel, semper in, velit.}
    \end{minipage}
\end{figure}

minipage Thanks a lot!

3
  • 2
    well the template doesn't compile for me. But beside this: that is the problem with such overloaded templates. There are tons of packages and settings and finding where it fails cost lots of time. Commented Dec 6, 2022 at 22:50
  • @UlrikeFischer I'm totally with you and I'm not gonna fall for it again. If it works, it's gold, if it fails, your doomed. For this one, I don't know whether I have the time left to re-create everything from the scratch ... P.S. To make it compile: (1) Kick tocstyle in packages.tex and style.tex (2) Kick \usetkzobj{all} and move tkz-fct in-front of tkz-euclide in packages-tikzpgf.tex (3) on l.25: \NewDocumentCommand\unit{om}{% to \RenewDocumentCommand\unit{om}{%.
    – Suuuehgi
    Commented Dec 6, 2022 at 23:18
  • LaTeX places the caption where you put it, but some packages (floatrow and float) move the caption around. See tex.stackexchange.com/questions/403661/… Commented Dec 7, 2022 at 4:02

2 Answers 2

1

Here's the example based on minipage. From the snippets I understand you prefer the top alignment.

\documentclass{article}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{ragged2e}
\usepackage{kantlipsum}  % For filler text
\usepackage{caption}
    \DeclareCaptionFormat{belowlabel}{#1#2}
    \captionsetup[figure]{
        format=belowlabel,
        position=top,
        singlelinecheck=false,
        skip=6pt,
    }


\begin{document}
\kant[1][1]

\begin{figure}[tbh]
    \begin{minipage}[t]{0.6\linewidth}
        \includegraphics[width=\linewidth,valign=T]{example-image}
    \end{minipage}\hfill
    \begin{minipage}[t]{\dimexpr0.4\linewidth-1em}
        \caption{\null}
        
        \RaggedRight Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante. Donec ullamcorper, felis non sodales commodo, lectus velit ultrices augue, a dignissim nibh lectus placerat pede. Vivamus nunc nunc, molestie ut, ultricies vel, semper in, velit.
    \end{minipage}
\end{figure}

\kant[2][1]
\end{document}

enter image description here


EDIT.
If this style must e intervened with a normal style, \captionseup needs to be inside an environment to make changes of local scope. The whole style can be enclosed in a macro:

\NewDocumentCommand\Figure{O{} m m}{%
  \begin{figure}[#1]
    \captionsetup{
      format=belowlabel,
      position=top,
      singlelinecheck=false,
      skip=6pt,
    }
    \begin{minipage}[t]{0.6\linewidth}
      \includegraphics[width=\linewidth,valign=T]{#2}
    \end{minipage}\hfill
    \begin{minipage}[t]{\dimexpr0.4\linewidth-1em}
      \caption{\null}
      \IfValueT{#3}{\notblank{#3}{\par\RaggedRight #3}{}}
    \end{minipage}
  \end{figure}}

Other images will follow the standard style. See the updated code and a screenshot

\documentclass{article}
\usepackage{etoolbox}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{ragged2e}
\usepackage{kantlipsum}  % For filler text
\usepackage{caption}
\DeclareCaptionFormat{belowlabel}{#1#2}

\NewDocumentCommand\Figure{O{} m m}{%
  \begin{figure}[#1]
    \captionsetup{
      format=belowlabel,
      position=top,
      singlelinecheck=false,
      skip=6pt,
    }
    \begin{minipage}[t]{0.6\linewidth}
      \includegraphics[width=\linewidth,valign=T]{#2}
    \end{minipage}\hfill
    \begin{minipage}[t]{\dimexpr0.4\linewidth-1em}
      \caption{\null}
      \IfValueT{#3}{\notblank{#3}{\par\RaggedRight #3}{}}
    \end{minipage}
  \end{figure}}


\begin{document}
\kant[1][1]

\Figure[tbh]{example-image}{%
  Nullam nec mi et neque pharetra sollicitudin.
  Praesent imperdiet mi nec ante.
  Donec ullamcorper, felis non sodales commodo, lectus velit ultrices augue, a dignissim nibh lectus placerat pede.
  Vivamus nunc nunc, molestie ut, ultricies vel, semper in, velit.}

\kant[1][2]

\begin{figure}[tbh]
  \centering
  \includegraphics[width=0.6\linewidth,valign=T]{example-image}
  \caption{%
    Nullam nec mi et neque pharetra sollicitudin.
    Praesent imperdiet mi nec ante.
    Donec ullamcorper, felis non sodales commodo, lectus velit ultrices augue, a dignissim nibh lectus placerat pede.
    Vivamus nunc nunc, molestie ut, ultricies vel, semper in, velit.}
\end{figure}

\kant[1][3]

\Figure{example-image-a}{}
\end{document}

enter image description here

2
  • That's certainly a nice way to do it but don't want to change the style globally. I will not touch this template again but for now, I'll stick to it. And thank you for the kantlipsum package! :D I didn't know about that one.
    – Suuuehgi
    Commented Jan 10, 2023 at 14:57
  • \captionseup can be moved inside environments and affect only such environments. Other images will keep the standard style. A good approach is to make a wrapper with a couple of parameters (see my edit).
    – Celdor
    Commented Jan 10, 2023 at 15:56
0

In addition to Celdor's answer I'd like to add a second, more down to earth, way for anyone else struggling with this using the aforementioned template: The template uses the floatrow package and one can change the style locally by using braces. E.g.

\documentclass[12pt]{scrartcl}

\usepackage{microtype,graphicx,floatrow,caption,kantlipsum}

\begin{document}

{
    \floatsetup[figure]
    {style=plain,capposition=beside,objectset=centering,
    capbesidewidth=.5\textwidth,capbesideposition=outside,
    floatwidth=sidefil}
    \captionsetup[figure]{format=plain}

    \begin{figure}
        \includegraphics[width=.4\textwidth]{example-grid-100x100pt}
        \caption{\kant[1][1]}
    \end{figure}
}

\begin{figure}
    \includegraphics[width=.4\textwidth]{example-grid-100x100pt}
    \caption{\kant[1][1]}
\end{figure}

\end{document}

rendered_code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .