0

I am trying to make some nice-looking captions for some photos. The problem is that when I keep the aspect ratio unchanged, the picture widths will be different and I have only been able to figure out how to declare a single caption width (and not several that adjust to each picture width).

A working example (whether or not it is minimal, I do not know) follows.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{tgbonum}
\usepackage{tikz}
\usepackage{caption}
\usepackage{float}
\usepackage{tcolorbox}

%\graphicspath{{/Users/...} (!NOTE! will not compile unless (1) your own graphics path is declared and (2) examplePhoto1 and examplePhoto2 names are suitably renamed)

\definecolor{captionColor}{RGB}{103,143,150}

\DeclareCaptionFormat{customCaption}{% \begin{tcolorbox}[ nobeforeafter, colback=captionColor, arc=0pt, outer arc=0pt, boxrule=0pt, colupper=white, %fontupper=\normal, boxsep=0pt ] #1#2#3 \end{tcolorbox}% } \captionsetup{format=customCaption,labelformat=empty,justification=raggedright,singlelinecheck=false,position=bottom,skip=0pt,textfont={it}} \setkeys{Gin}{width=\linewidth}

\begin{document}

The beginning of the document stretches the full text width. \vspace{15mm}

\begin{minipage}[t]{0.60\textwidth}\vspace{0pt} There will be some text on the left side of the page. The start of this text needs to be vertically aligned with the top of the other minipage. \end{minipage} \quad \quad \quad \begin{minipage}[t]{0.29\textwidth}\vspace{0pt} \captionsetup{type=figure} \includegraphics[width=\linewidth,height=.9\linewidth,keepaspectratio]{examplePhoto1} {\caption[]{Caption to first picture}} \vspace{6mm} \includegraphics[width=\linewidth,height=.9\linewidth,keepaspectratio]{examplePhoto2} {\caption[]{Caption to second picture (which will probably not be the same width as the first picture)}} \end{minipage} \end{document}

Sam
  • 141
  • And more or less the same solutions in another question: https://tex.stackexchange.com/questions/422359/how-to-set-width-of-caption-to-width-of-figure – Marijn Sep 05 '21 at 09:24
  • Another approach is to use an individual minipage for each figure as in https://tex.stackexchange.com/a/166721/ – Marijn Sep 05 '21 at 09:26
  • And there is also the boxhandler package for this kind of functionality. – Marijn Sep 05 '21 at 09:30

0 Answers0