我想并排显示两个图形,但无论小页面宽度如何,标题似乎都会重叠。有没有办法局部减小标题大小?或者让它尊重边距?
这是我的代码:
\documentclass[12pt,a4paper,openright,oneside]{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{tikz}
\newcommand{\exedout}{
\begin{tikzpicture}
\path node (LL) {}
++ (0.8\textwidth, 0.4\textheight) node (UR) {}
(LL -| UR) node (LR) {}
(LL |- UR) node (UL) {};
\draw (LL) rectangle (UR) (LL) -- (UR) (UL) -- (LR);
\end{tikzpicture}
}
\begin{document}
\begin{figure}
\begin{minipage}{0.45\textwidth}
\exedout
\caption{Caption number one with enough text to overlap with caption number two bla... bla...bla... bla...bla... bla...}
\end{minipage}%
\begin{minipage}{0.45\textwidth}
\exedout
\caption{Caption number two with enough text to overlap with caption number two bla... bla...bla... bla...bla... bla...}
\end{minipage}
\end{figure}
\end{document}
输出:
我怎样才能解决这个问题?
PD:我如何使用我在此网站上多次见过的示例图像(例如“example-image-a”等)?
答案1
由于您使用的是caption
包,因此可以轻松width
根据需要设置标题的。\captionsetup{width=0.4\textwidth}
例如,您可以添加,以将标题文本的宽度限制为仅0.4\textwidth
。
\documentclass[12pt,a4paper,openright,oneside]{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{tikz}
\newcommand{\exedout}{
\begin{tikzpicture}
\path node (LL) {}
++ (0.8\textwidth, 0.4\textheight) node (UR) {}
(LL -| UR) node (LR) {}
(LL |- UR) node (UL) {};
\draw (LL) rectangle (UR) (LL) -- (UR) (UL) -- (LR);
\end{tikzpicture}
}
\begin{document}
\begin{figure}
\captionsetup{width=0.4\textwidth}
\begin{minipage}{0.45\textwidth}\centering
\exedout
\caption{Caption number one with enough text to overlap with caption number two bla... bla...bla... bla...bla... bla...}
\end{minipage}%
\begin{minipage}{0.45\textwidth}\centering
\exedout
\caption{Caption number two with enough text to overlap with caption number two bla... bla...bla... bla...bla... bla...}
\end{minipage}
\end{figure}
\end{document}
另一个重要的观察结果是minipage
s 之间没有空格。因此,如果你只是\hfill
在它们之间添加,问题就完全消失了(当然,假设两个宽度的总和小于 a linewidth
):
\begin{figure}
\begin{minipage}{0.45\textwidth}\centering
\exedout
\caption{Caption number one with enough text to overlap with caption number two bla... bla...bla... bla...bla... bla...}
\end{minipage}%
\hfill
\begin{minipage}{0.45\textwidth}\centering
\exedout
\caption{Caption number two with enough text to overlap with caption number two bla... bla...bla... bla...bla... bla...}
\end{minipage}
\end{figure}
答案2
使用 floatrow
:您可以使用可选参数\ffigbox
(或\tabbox
对于表格)控制浮动框的宽度:
\documentclass[12pt,a4paper,openright,oneside]{article}
\usepackage{graphicx}
\usepackage{caption, floatrow}
\usepackage{tikz}
\newcommand{\exedout}{
\begin{tikzpicture}
\path node (LL) {}
++ (0.8\linewidth, 0.4\textheight) node (UR) {}
(LL -| UR) node (LR) {}
(LL |- UR) node (UL) {};
\draw (LL) rectangle (UR) (LL) -- (UR) (UL) -- (LR);
\end{tikzpicture}
}
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.3pt}
\begin{document}
\begin{figure}
\floatsetup{floatrowsep = qquad}
\begin{floatrow}
\ffigbox[0.45\textwidth]{ \caption{Caption number one with enough text to overlap with caption number two bla... bla...bla... bla...bla... bla...}}{\exedout}
\caption{Caption number one with enough text to overlap with caption number two bla... bla...bla... bla...bla... bla...}
\ffigbox[0.45\textwidth]{\caption{Caption number two with enough text to overlap with caption number two bla... bla...bla... bla...bla... bla...}}{\exedout}
\end{floatrow}
\end{figure}
\end{document}