一个标题中可以有多个换行符吗?

一个标题中可以有多个换行符吗?

我正在为数学学生写笔记,我有直角三角形,下面有 3 行注释作为标题。我可以将标题放在两行上,不能再多了。我想知道我尝试做的事情是否可行,或者是否有解决方法。我的代码

\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$}%

上述命令给出“未定义的控制序列”,但下面的命令有效

\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}

我希望在每个三角形下方添加两行,因为上面的代码显示不起作用。这可能吗?如能提供帮助,我们将不胜感激 输出

答案1

也许这是对你的问题更好的解决方案?假设,你想将这些仅仅相似的三角形作为一个浮点数呈现,包含三个子图。

我将标题字体大小的定义放入序言中,以便让一个定义以相同的方式作用于文档中的所有标题。

您必须加载包subcaption。在某些情况下,subcaption不起作用,例如 Springer 期刊等。在这种情况下,您必须使用包subfigure

编辑:根据评论,我改变了我的 MWE。

  1. 我添加了缺失的节点。
  2. 我添加了缺失的角度,并标注为$\theta
  3. 为了避免不必要的输入,我创建了一个新命令\triang\triangle已定义),并采用(截至目前) 3 个参数来标记三行。

我试图画出角度,$\theta但只是猜测了结束角度。看来,30° 也应该满足。为了穿过斜边,我增加了角度以end angle确保万无一失,并剪掉了三角形外部的所有内容。

更好的方法是,通过定义第四个参数来定义一个变量三角形,表示所需的角度。也许我可以这样做,稍后会添加该示例。

到目前为止,这是我的 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}

输出如下所示:

在此处输入图片描述

因此,这是我的第二次尝试。我进行了以下更改:

  1. 我重新设计了宏\triang,使其基于给定的角度。现在角度在第一个参数中定义,即 #1。
  2. 我将点“A”定义为原点(0,0)
  3. 我切换到极坐标,以点“B”为端点绘制斜边。现在显示\coordinate [label=above:$B$] (B) at (#1:\@triaglen);为其中#1表示可变角度和\@triaglen斜边的定义长度。
  4. 为了使三角形的路径正常工作,TikZ 必须根据给定的角度计算线 BC 与斜边“AB”以及 x 轴本身的交点。定义现在为\coordinate [label=right:$C$] (C) at (#1:\@triaglen |- 0,0);。请注意坐标。它写为一组坐标和标记|-。看看TikZ-手册在第38页。
  5. 为了调整角度 Theta 标签的位置,我还更改了它的定义:\coordinate [label=right:$\theta$] (Theta) at ({#1/2}:\@arclen+.1);。Theta 现在设置为给定角度的一半(#1我希望您还记得,即 !)。
  6. 现在我可以绘制三角形了。由于角度本身已经定义,我可以使用该角度在连接点“A”和“B”的线上倾斜标签。
  7. 再次强调:由于角度是精确已知的,我不必冒险将弧线画得更长,并剪掉所有突出的部分。因此,clip删除了上述 MWE 中的 -command。

我还定义了一些内部变量\@triaglen\@sqlen\@arcradii,以便能够一致地更改三角形的大小。要使用@- 符号,我必须使用\makeatletter\makeatother。如果您在样式文件中隐藏\newcommands 和\defs ,则不必提供\makeatletter\makeatother。 的用法@是使这些命令和变量成为“内部”的。要更改三角形大小,我添加了一个用户空间命令\trianglelength{},它接受一个参数,即斜边的新长度。

我在第一个三角形中演示了 的用法\trianglelength。请注意,新大小仅限于该三角形subfigure,不会影响第二个和第三个三角形。

这是完整的高级 MWE。(正如评论中指出的那样,我更改了标题的布局,使其对齐而不是居中。)

\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
%% \@arcradii, the radius of the angle arc.
\makeatletter%
\def\@triaglen{3.0}%
\def\@sqlen{\@triaglen/12}%
\def\@arcradii{\@triaglen/5}%
\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 angle=#1, radius=\@arcradii] --  cycle;
  \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}

其结果如下:

在此处输入图片描述

相关内容