# Can one have more than one line break in a caption?

I am writing notes for mathematics students and I have right triagles with notes below them as caption on 3 lines. I am able to put the caption on two lines not more. i am wondering if what am trying to do is possible, or if there is a workaround. my code

\documentclass{report}
\usepackage[a4paper,width=150mm,top=25mm,left=15mm,bottom=25mm,right=15mm,bindingoffset=10mm]{geometry}
\usepackage[justification=centering]{caption}
\newcommand\captionlinebreak{\ifsinglelinecaption\space\else\\\fi}

\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{shapes.geometric, decorations.pathreplacing, matrix, angles, quotes, arrows, arrows.meta, datavisualization}
\usepackage{pgfplots}

\begin{document}
\begin{minipage}[b]{0.3\linewidth}
\centering
\begin{tikzpicture}[scale=1.0]%,cap=round,>=latex]
\coordinate [label=left:] (A) at (-1.5cm,-1.cm);
\coordinate [label=right:] (C) at (1.5cm,-1.0cm);
\coordinate [label=above:] (B) at (1.5cm,1.0cm);
\draw (A) -- node[above] {$a$} (B) -- node[right] {$u$} (C) -- node[below] {$\sqrt{a^{2}-u^{2}}$} (A);
\draw (1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);
\end{tikzpicture}
\captionsetup{font=footnotesize}%
\captionof{figure}{i)\\ $u=a\sin\theta$\\ $\sqrt{a^{2}-u^{2}}=a\cos\theta$\\  $du=a\cos\thetad\theta$}%


The above command gives "undefined control sequence" but the one below works

\captionof{figure}{i)\\ $u=a\sin\theta$}
\end{minipage}
\begin{minipage}[b]{0.3\linewidth}
\centering
\begin{tikzpicture}[scale=1.0]%,cap=round,>=latex]
\coordinate [label=left:] (A) at (-1.5cm,-1.cm);
\coordinate [label=right:] (C) at (1.5cm,-1.0cm);
\coordinate [label=above:] (B) at (1.5cm,1.0cm);
\draw (A) -- node[above,rotate=35] {$\sqrt{a^{2}+u^{2}}$} (B) -- node[right] {$u$} (C) -- node[below] {$a$} (A);
\draw (1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);
\end{tikzpicture}%
\captionsetup{font=footnotesize}%
\captionof{figure}{ii)}%
\end{minipage}
\begin{minipage}[b]{0.3\linewidth}
\centering
\begin{tikzpicture}[scale=1.0]%,cap=round,>=latex]
\coordinate [label=left:] (A) at (-1.5cm,-1.cm);
\coordinate [label=right:] (C) at (1.5cm,-1.0cm);
\coordinate [label=above:] (B) at (1.5cm,1.0cm);
\draw (A) -- node[above] {$u$} (B) -- node[right] {$\sqrt{u^{2}-a^{2}}$} (C) -- node[below] {$a$} (A);
\draw (1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);
\end{tikzpicture}
\captionsetup{font=footnotesize}
\captionof{figure}{iii)}
\end{minipage}
\end{document}


Below each triangle I would like to have two additional lines as in the code indicated as not working above. Is this possible? Help will be appreciated

• The error is \thetad -- this is an unknown command (a typo?) Fixing this, it will work, so error is not related to \caption or multi lines at all. (I've also deleted the irrelevant tag latex3) – user31729 Jan 1 '17 at 7:44
• You should use the onehalfspacing option for caption (requires \usepackage{setspace} in order to improve the spacing in multiline captions – user31729 Jan 1 '17 at 8:04
• Thanks @Christian, I really did not see my \thetad typo. I am really grateful. May the New Year 2017 be prosperous and fruitful for you. – Zilore Mumba Jan 1 '17 at 8:43
• @ZiloreMumba: happy new year to you. I am not sure, to understand your question exactly, I beg your pardon. Do you want to have one figure, containing three triangles or do you want to present three independent figures, each presenting one triangle? I was concerned, as your captions show different counters. The figure-counter in arabic and the small roman numbers. I'd say, the three triangles are only slight variations of the theme and should hence be presented as one figure (arabic number) with three subfigures (roman numbers). – Jan Jan 1 '17 at 9:39
• @Jan: Indeed, subcaption would be better solution – user31729 Jan 1 '17 at 10:04

Maybe this is a better solution to your question? Assuming, you want to present those merely similar triangles as a group presented in one float, containing three subfigures.

I placed the definition of the caption fontsizes into the preamble, to have one definition acting in the same way to all captions in your document.

You have to load package subcaption. In some cases, subcaption does not work, e.g. with springer journals, etc. In that case, you'll have to work around with package subfigure.

EDIT: according to the comment, I changed my MWE.

1. I added the missing nodes.
2. I added the missing angle and labeled it with $\theta 3. To avoid unnecessary typing, I created a new command \triang (as \triangle is already defined), taking (as of now) 3 arguments for the labeling of the three lines. My attempt, to draw in the angle $\theta was just a guess of the ending angle. It seems, that 30° would have also met. In order, to cross the hypothenuse, I increased the end angleto be sure and clipped everything outside of the triangle away.

It would be better, to define a variable triangle by defining a fourth argument, denoting the wanted angle. Maybe I'll be able to do so and will add that example later.

As of now, this is my MWE:

\documentclass{report}
\usepackage[a4paper,width=150mm,top=25mm,left=15mm,bottom=25mm,right=15mm,bindingoffset=10mm]{geometry}
\usepackage[justification=centering]{caption}
\usepackage{subcaption}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{shapes.geometric, decorations.pathreplacing, matrix,
angles, quotes, arrows, arrows.meta, datavisualization}
\usepackage{pgfplots}

\newcommand\captionlinebreak{\ifsinglelinecaption\space\else\\\fi}
%% better to be defined in the preamble?
\captionsetup{font=footnotesize}%

%% Te speed up the programming: define this command, to draw a
%% triangle.  The arguemtns denote:
%%      #1: label of the AC-line (hypothenuse)
%%      #2: label of the CB-line (opposite line, Gegenkathethe)
%%      #3: label of the AB-line (adjacent line, Ankathethe)
\newcommand{\triang}[3]{%
\begin{tikzpicture}[scale=1.0%
% ,cap=round
% ,>=latex
]%
%% Define the ccordinates, where to put the corners of the
%% triangle.  These were given by the OP.  I'd suggest to put
%% Point A on the origin, which is (0,0)
\coordinate [label=left:$A$] (A) at (-1.5cm,-1.cm);%
\coordinate [label=above:$B$] (B) at (1.5cm,1.0cm);%
\coordinate [label=right:$C$] (C) at (1.5cm,-1.0cm);%
%% coordinates of the angle Theta
\coordinate [label=right:$\theta$] (Theta) at (-1cm, -0.8cm);%
%% draw the trinangle
\draw (A) -- node[above, rotate=35] {#1} (B) -- node[right] {#2} (C) --%
node[below] {#3} (A);%
%% draw the rectangular corner
\draw (1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);%
%% Now draw the angle arc.  To be sure, that the arc will join the
%% hypothenuse, lets make the end angle somewhat bigger, in order
%% to protrude the hypothenuse.  Use clip to cut it in the
%% hypothenuse.
\clip (A) -- (B) -- (C) -- (A);%
\draw (-1.1cm, -1cm) arc[start angle=0, end angle=40, radius=4mm];%
\end{tikzpicture}%
}

\begin{document}
\begin{figure}
\centering
\begin{subfigure}[b]{0.3\linewidth}
\centering
\triang{$c$}{$a$}{$\sqrt{c^{2}-a^{2}}$}
\caption{$u=a\sin\theta$}
\end{subfigure}%
\begin{subfigure}[b]{0.3\linewidth}
\centering
\triang{$\sqrt{a^2 + b^2}$}{$a$}{$b$}
\caption{$u=\sqrt{a^2 + u^2} \sin \theta$}
\end{subfigure}%
\begin{subfigure}[b]{0.3\linewidth}
\centering
\triang{$c$}{$\sqrt{c^2 - b^2}$}{$b$}
\caption{$a=u \cos \theta$}
\end{subfigure}
%% Now the main caption.  Of course, captions may have more than one line.
\caption{Triangle calculations by means of trigonometric functions.\\
To utilize trigonometric functions, you'll have to apply them on a
triangle, which has a right angle.  There are the functions Sinus,
Cosinus and Tanges.  Sinus is defined as the fraction of the length
of the opposite site to the length of the hypothenuse.}
\label{fig:triangle}
\end{figure}
\end{document}


Output looks like this:

So, here is my second attempt. I changed the following:

1. I redesigned the macro \triang to be based on a given angle. The angle is now defined in the first argument, which is #1.
2. I defined point "A" to be in the origin (0,0).
3. I switched to polar coordinates, to draw the hypothenuse ending in point "B". It reads now \coordinate [label=above:$B$] (B) at (#1:\@triaglen); where #1 denotes the variable angle and \@triaglen an defined length of the hypothenuse.
4. In order to get the path of the triangle working, TikZ has to compute the intersections of line BC with the hypothenuse "AB" and with the x-axis itself, according to the given angle. The definition reads now \coordinate [label=right:$C$] (C) at (#1:\@triaglen |- 0,0);. Please note the coordinates. It is written as a set of to coordinates and the marker |-. Have a look at the TikZ-manual on page 38.
5. In order to adapt the location of the label of the angle Theta, I changed its definition also: \coordinate [label=right:$\theta$] (Theta) at ({#1/2}:\@arclen+.1);. Theta is now set at half of the given angle (which was #1, I hope you recall!).
6. Now I am able to draw the triangle. As the angle itself is defined, I can use that angle for tilting the label on the line connecting points "A" and "B".
7. Again: as the angle is exactly known, I do not have to make a safe bet and draw the arc longer as it needs and clip everything protruding away. Hence, the clip-command from the above MWE was deleted.

I also defined some internal variables \@triaglen, \@sqlen and \@arcradii, to enable consistent changes of the size of the triangle. To use the @-sign, I had to use \makeatletter and \makeatother. If you hide the \newcommands and \defs in a style file, you don't have to give \makeatletter and \makeatother. The usage of @ is to make those commands and variables "internal". To change the trianglesize, I added a user space command \trianglelength{}, taking one argument, which is the new length of the hypothenuse.

I demonstrated the usage of \trianglelength at the first triangle. Notice, that the new size is local to that subfigure and does not affect the second and third triangle.

Here is the complete, advanced MWE. (As also noted in the comments, I changed the layout of the caption, to be justified instead of centered.)

\documentclass{report}
\usepackage[a4paper,width=150mm,top=25mm,left=15mm,bottom=25mm,right=15mm,bindingoffset=10mm]{geometry}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, decorations.pathreplacing, matrix,
angles, quotes, arrows, arrows.meta, datavisualization}
\usepackage{pgfplots}

%% better to be defined in the preamble?
\captionsetup{font=footnotesize}%

%% Te speed up the programming: define this command, to draw a
%% triangle.  The arguments denote:
%%      #1: angle of the triangle (0°--90°)
%%      #2: label of the AC-line (hypothenuse)
%%      #3: label of the CB-line (opposite line, Gegenkathethe)
%%      #4: label of the AB-line (adjacent line, Ankathethe)
%% Now the Point A will be in the origin.  To get this working, I will
%% use polar coordinates.  To be more flexible, I define the internal
%% factor \@triaglen, which is the length of the hypothenuse.  Derived
%% from that are \@sqlen, the size of the square corner rectangle and
\makeatletter%
\def\@triaglen{3.0}%
\def\@sqlen{\@triaglen/12}%
\newcommand{\triang}[4]{%
\begin{tikzpicture}[scale=1.0%
% ,cap=round
% ,>=latex
]%
%% first point "A" is the origin
\coordinate [label=left:$A$] (A) at (0,0);%
%% second is the polar coordinate of the angle given in #1, and a
%% freely defined length in \@triaglen
\coordinate [label=above:$B$] (B) at (#1:\@triaglen);%
%% The last point is the intersection of a vertical line through
%% the second point and the x-axis.  This is denoted in TikZ with
%% "|-".  See the TikZ-manual/tutorial on page 38
\coordinate [label=right:$C$] (C) at (#1:\@triaglen |- 0,0);%
%% coordinates of the angle Theta.  Theta should be in the middle
%% between x-axis and the hpothenuse, which is in polar
%% coordinates the half of #1: #1/2
\coordinate [label=right:$\theta$] (Theta) at ({#1/2}:\@arcradii+.1);%
%% draw the trinangle
\draw (A) -- node[above, rotate=#1] {#2} (B) -- node[right] {#3} (C) --%
node[below] {#4} (A);%
%% draw the rectangular corner
\draw[thin] (C) rectangle +(-\@sqlen,\@sqlen);%
%% Draw the angle arc
\draw[thin] (A) -- (\@arcradii,0)  arc[start angle=0,
\end{tikzpicture}%
}
%% This could be a user space command, to change the length of the
%% hypothenuse
\newcommand{\triaglength}[1]{%
\def\@triaglen{#1}}%
\makeatother

\begin{document}
\begin{figure}
\centering
\begin{subfigure}[b]{0.3\linewidth}
\centering
%% Change the size of the triag (local to this subfigure)
\triaglength{4.0}
\triang{30}{$c$}{$a$}{$\sqrt{c^{2}-a^{2}}$}
\caption{$a=c \sin\theta$}
\end{subfigure}%
\begin{subfigure}[b]{0.3\linewidth}
\centering
\triang{40}{$\sqrt{a^2 + b^2}$}{$a$}{$b$}
\caption{$Bu=c \cos \theta$}
\end{subfigure}%
\begin{subfigure}[b]{0.3\linewidth}
\centering
\triang{50}{$c$}{$\sqrt{c^2 - b^2}$}{$b$}
\caption{$a=\sqrt{c^2 - b^2}$}
\end{subfigure}
%% Now the main caption.  Of course, captions may have more than one line.
\caption{Triangle calculations by means of trigonometric functions.\\
To utilize trigonometric functions, you'll have to apply them on a
triangle, which has a right angle.  There are the functions Sinus,
Cosinus and Tanges.  Sinus is defined as the fraction of the length
of the opposite site to the length of the hypothenuse.}
\label{fig:triangle}
\end{figure}
\end{document}


And its result:

• In this case I would not use centering as justification, but this is a personal view. No need to change it really. – user31729 Jan 1 '17 at 10:17
• labels of triangles coordinates are not used ... I would delete them. – Zarko Jan 1 '17 at 10:24
• @Zarko: I used them now to set the names of the points "A", "B" and "C". – Jan Jan 1 '17 at 13:48
• @ChristianHupfer: I agree and hence removed that from my second example. – Jan Jan 1 '17 at 13:48