我正在尝试将两个 tikzpicture 放在两个小页面中,但它们的标题重叠了。这是我使用的代码。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper,top=2.5cm,bottom=2.50cm,left=3.00cm,right=3.00cm]{geometry}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{amsmath,amssymb,commath}
\usepackage{caption}
\usepackage{tikz}
\usepackage[RPvoltages]{circuitikz}
\usepackage{tkz-euclide}
\usepackage{subcaption}
\captionsetup {
format=plain,
width=0.80\textwidth,
font=normal,
labelfont=bf,
figurename = Fig. ,
tablename = Tab.
}
\title{\Huge{\textbf{Test}}}
\author{me}
\date{}
\begin{document}
\maketitle
\begin{figure}
\centering
\begin{minipage}{0.4\textwidth}
\centering
\begin{tikzpicture}
\centering
\draw [<->,thick] (0,2.8) node (yaxis) [left] {$t$}
|- (2.8,0) node (xaxis) [right] {$x$};
\draw[thick]
(0,0) -- (0,-2.8)
(0,0) -- (-2.8,0);
\draw[green, ultra thick] (0,-2.90) -- (0,2.90);
\draw[dashed]
(0,2.90) -- (0,2.95)
(0,-2.90) -- (0,-2.95);
\end{tikzpicture}
\captionof{figure}{Worldline of a static point-like source}
\label{fig:static_source}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\centering
\begin{tikzpicture}
\draw [<->,thick] (0,2.8) node (yaxis) [left] {$t$}
|- (2.8,0) node (xaxis) [right] {$x$};
\draw[thick]
(0,0) -- (0,-2.8)
(0,0) -- (-2.8,0);
\node[mark size = 3pt, green] at (0,0) {\pgfuseplotmark{*}};
\draw[dashed]
(0,2.90) -- (0,2.95)
(0,-2.90) -- (0,-2.95);
\end{tikzpicture}
\captionof{figure}{Worldline of an instantaneous point-like source}
\label{fig:inst_source}
\end{minipage}
\end{figure}
\end{document}
有人能帮帮我吗?我发现即使没有设置字幕,它也能正常工作。
答案1
- 正如我在评论中提到的,问题在于您的标题设置。如果您希望标题宽度为环境宽度的 0.8,则它所在的位置比您需要在此环境中设置的宽度要大。
- 在您的情况下,您不需要使用,
\captionof
因为标题位于figure
浮点数内。 \centering
删除里面的命令tikzpicture
(这没有坏处,也没有任何好处)- 使用
\hfill
betweenminipage
s 将它们推开,以便它们周围的所有水平空间相等。
可能的 MWE(其中我删除了与您的问题无关的所有内容)是:
\documentclass{article}
\usepackage[a4paper,
hmargin=3cm, vmargin=2.5cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{caption,subcaption}
\captionsetup{ format=plain,
labelfont=bf,
figurename = Fig. ,
tablename = Tab.}
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
\begin{minipage}{0.4\textwidth}
\centering
\begin{tikzpicture}
\draw [<->,thick] (0,2.8) node (yaxis) [left] {$t$}
|- (2.8,0) node (xaxis) [right] {$x$};
\draw[thick]
(0,0) -- (0,-2.8)
(0,0) -- (-2.8,0);
\draw[green, ultra thick] (0,-2.90) -- (0,2.90);
\draw[dashed]
(0,2.90) -- (0,2.95)
(0,-2.90) -- (0,-2.95);
\end{tikzpicture}
\captionsetup{width=0.80\textwidth}
\caption{Worldline of a static point-like source}
\label{fig:static_source}
\end{minipage}\hfil
\begin{minipage}{0.4\textwidth}
\centering
\begin{tikzpicture}
\draw [<->,thick] (0,2.8) node (yaxis) [left] {$t$}
|- (2.8,0) node (xaxis) [right] {$x$};
\draw[thick]
(0,0) -- (0,-2.8)
(0,0) -- (-2.8,0);
\node[mark size = 3pt, green] at (0,0) {\pgfuseplotmark{*}};
\draw[dashed]
(0,2.90) -- (0,2.95)
(0,-2.90) -- (0,-2.95);
\end{tikzpicture}
\captionsetup{width=0.80\textwidth}
\caption{Worldline of an instantaneous point-like source}
\label{fig:inst_source}
\end{minipage}
\end{figure}
\end{document}
答案2
只需引入\hspace{2pc}
标签就会在图像之间添加更多水平空间,如下MWE
所示:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper,top=2.5cm,bottom=2.50cm,left=3.00cm,right=3.00cm]{geometry}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{amsmath,amssymb,commath}
\usepackage{caption}
\usepackage{tikz}
\usepackage[RPvoltages]{circuitikz}
\usepackage{tkz-euclide}
\usepackage{subcaption}
\title{\Huge{\textbf{Test}}}
\author{me}
\date{}
\begin{document}
\maketitle
\begin{figure}
\begin{minipage}{0.4\textwidth}
\centering
\begin{tikzpicture}
\centering
\draw [<->,thick] (0,2.8) node (yaxis) [left] {$t$}
|- (2.8,0) node (xaxis) [right] {$x$};
\draw[thick]
(0,0) -- (0,-2.8)
(0,0) -- (-2.8,0);
\draw[green, ultra thick] (0,-2.90) -- (0,2.90);
\draw[dashed]
(0,2.90) -- (0,2.95)
(0,-2.90) -- (0,-2.95);
\end{tikzpicture}
\captionof{figure}{Worldline of a static point-like source}
\label{fig:static_source}
\end{minipage}\hspace{2pc}
\begin{minipage}{0.4\textwidth}
\centering
\begin{tikzpicture}
\draw [<->,thick] (0,2.8) node (yaxis) [left] {$t$}
|- (2.8,0) node (xaxis) [right] {$x$};
\draw[thick]
(0,0) -- (0,-2.8)
(0,0) -- (-2.8,0);
\node[mark size = 3pt, green] at (0,0) {\pgfuseplotmark{*}};
\draw[dashed]
(0,2.90) -- (0,2.95)
(0,-2.90) -- (0,-2.95);
\end{tikzpicture}
\captionof{figure}{Worldline of an instantaneous point-like source}
\label{fig:inst_source}
\end{minipage}
\end{figure}
\end{document}
输出