解决方案:通过更改字幕设置并添加“raggedright”,我能够解决问题
\captionsetup[figure]{font=small,labelfont=bf, singlelinecheck=false, justification=raggedright, skip=5pt}
我有一堆图表,但我在标题对齐方面遇到了一些问题,而其他所有关于此问题的帖子都无法解决问题。我想要一个垂直对齐,以便所有图表的标题都从同一位置开始(见图),但该怎么做呢?
短代码:
\documentclass[11pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{float}
\usepackage{subcaption}
\captionsetup[figure]{font=small,labelfont=bf, skip=5pt} %default=10pt
\begin{document}
\begin{figure}[t][H]
\hspace*{-2cm}
\begin{minipage}{8.25cm}
\begin{tikzpicture}[scale=1]
\caption{Longevity - Minimum Variance}
\label{LongGraph5}
\end{minipage}
\begin{minipage}[t]{8.25cm}
\begin{tikzpicture}[scale=1]
\caption{Longevity - Tangency Portfolio}
\label{LongGraph6}
\end{minipage}
\end{figure}
\begin{figure}[H]
\hspace*{-2cm}
\begin{minipage}[t]{8.25cm}
\begin{tikzpicture}[scale=1]
\caption{Longevity - Sortino}
\label{LongGraph7}
\end{minipage}
\begin{minipage}[t]{8.25cm}
\begin{tikzpicture}[scale=1]
\caption{Longevity - Risk Longevity}
\label{LongGraph8}
\end{minipage}
\end{figure}
\end{document}
最小工作示例:
\documentclass[11pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{float}
\usepackage{subcaption}
\usepackage{mwe}
\captionsetup[figure]{font=small,labelfont=bf, skip=5pt} %default=10pt
\begin{document}
\begin{figure}[H]
\hspace*{-2cm}
\begin{minipage}[t]{8.25cm}
\includegraphics{example-image-1x1}
\caption{Longevity - Minimum Variance}
\label{LongGraph5}
\end{minipage}
\begin{minipage}[t]{8.25cm}
\includegraphics{example-image-1x1}
\caption{Longevity - Tangency Portfolio}
\label{LongGraph6}
\end{minipage}
\end{figure}
\begin{figure}[H]
\hspace*{-2cm}
\begin{minipage}[t]{8.25cm}
\includegraphics{example-image-1x1}
\caption{Longevity - Sortino}
\label{LongGraph7}
\end{minipage}
\begin{minipage}[t]{8.25cm}
\includegraphics{example-image-1x1}
\caption{Longevity - Risk Longevity}
\label{LongGraph8}
\end{minipage}
\end{figure}
\end{document}
编辑:包括图表的代码
\documentclass[11pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{float}
\usepackage{subcaption}
\captionsetup[figure]{font=small,labelfont=bf, skip=5pt} %default=10pt
%Color definitions
\definecolor{green}{RGB}{0, 102, 0}
\definecolor{blue1}{RGB}{0, 125, 255}
\definecolor{blue2}{RGB}{0, 102, 204}
\definecolor{blue3}{RGB}{0, 76, 153}
\definecolor{blue4}{RGB}{0, 51, 102}
\begin{document}
\section{Bonus Potential - Side by Side}
\begin{figure}[H]
\hspace*{-2cm}
\begin{minipage}[t]{8.25cm}
\begin{tikzpicture}[scale=1]
\begin{axis}[
xlabel={Bonus Potential (bn)},
ylabel={Frequency},
xmin=0, xmax=600,
ymin=0, ymax=80,
xtick={0,100, 200,300,400,500,600},
ytick={0,10,20,30,40,50,60,70,80},
xtick pos=bottom,ytick pos=left,
legend pos=north west,
legend style={font=\tiny}]
\legend{-20\%, -10\%, 0\%*, +10\%, +20\%},
\addplot[color=blue1, style={line width=0.7pt},smooth]
coordinates {
(120,0)
(180,0)
(240,39)
(300,55)
(360,6)
(420,0)
};
\addplot[color=blue2,style={line width=0.8pt}, smooth]
coordinates {
(120,0)
(180,1)
(240,30)
(300,59)
(360,9)
(420,1)
(480,0)
};
\addplot[color=green,style={line width=0.9pt}, smooth]
coordinates {
(120,0)
(180,5.8)
(240,59.8)
(300,34.2)
(360,0.2)
(420,0)
};
\addplot[color=blue3,style={line width=0.9pt}, smooth]
coordinates {
(120,0)
(180,1)
(240,31)
(300,62)
(360,6)
(420,0)
};
\addplot[color=blue4,style={line width=1pt}, smooth]
coordinates {
(120,0)
(180,1)
(240,34)
(300,52)
(360,13)
(420,0)
};
\end{axis}
\end{tikzpicture}
\caption{Longevity - Minimum Variance}
\label{LongGraph5}
\end{minipage}
\begin{minipage}[t]{8.25cm}
\begin{tikzpicture}[scale=1]
\begin{axis}[
xlabel={Bonus Potential (bn)},
ylabel={Frequency},
xmin=0, xmax=600,
ymin=0, ymax=80,
xtick={0,100, 200,300,400,500,600},
ytick={0,10,20,30,40,50,60,70,80},
xtick pos=bottom,ytick pos=left,
legend pos=north west,
legend style={font=\tiny}]
\legend{-20\%, -10\%, 0\%*, +10\%, +20\%},
\addplot[color=blue1, style={line width=0.7pt},smooth]
coordinates {
(180,0)
(240,4)
(300,35)
(360,51)
(420,10)
(480,0)
};
\addplot[color=blue2,style={line width=0.8pt}, smooth]
coordinates {
(180,0)
(240,1)
(300,31)
(360,49)
(420,18)
(480,1)
(540,0)
};
\addplot[color=green,style={line width=1pt}, smooth]
coordinates {
(180,0)
(240,10.5)
(300,56.4)
(360,32.5)
(420,0.6)
(480,0)
};
\addplot[color=blue3,style={line width=0.9pt}, smooth]
coordinates {
(180,0)
(240,31)
(300,53)
(360,16)
(420,0)
};
\addplot[color=blue4,style={line width=1pt}, smooth]
coordinates {
(180,0)
(240,1)
(300,33)
(360,43)
(420,23)
(480,0)
};
\end{axis}
\end{tikzpicture}
\caption{Longevity - Tangency Portfolio}
\label{LongGraph6}
\end{minipage}
\end{figure}
\begin{figure}[H]
\hspace*{-2cm}
\begin{minipage}[t]{8.25cm}
\begin{tikzpicture}[scale=1]
\begin{axis}[
xlabel={Bonus Potential (bn)},
ylabel={Frequency},
xmin=0, xmax=600,
ymin=0, ymax=80,
xtick={0,100, 200,300,400,500,600},
ytick={0,10,20,30,40,50,60,70,80},
xtick pos=bottom,ytick pos=left,
legend pos=north west,
legend style={font=\tiny}]
\legend{-20\%, -10\%, 0\%*, +10\%, +20\%},
\addplot[color=blue1, style={line width=0.7pt},smooth]
coordinates {
(180,0)
(240,31)
(300,53)
(360,16)
(420,0)
};
\addplot[color=blue2,style={line width=0.8pt}, smooth]
coordinates {
(180,0)
(240,37)
(300,45)
(360,17)
(420,1)
(480,0)
};
\addplot[color=green,style={line width=0.9pt}, smooth]
coordinates {
(120,0)
(180,3.3)
(240,50)
(300,46.3)
(360,0.4)
(420,0)
};
\addplot[color=blue3,style={line width=0.9pt}, smooth]
coordinates {
(180,0)
(240,31)
(300,53)
(360,16)
(420,0)
};
\addplot[color=blue4,style={line width=1pt}, smooth]
coordinates {
(180,0)
(240,29)
(300,55)
(360,16)
(420,0)
};
\end{axis}
\end{tikzpicture}
\caption{Longevity - Sortino}
\label{LongGraph7}
\end{minipage}
\begin{minipage}[t]{8.25cm}
\begin{tikzpicture}[scale=1]
\begin{axis}[
xlabel={Bonus Potential (bn)},
ylabel={Frequency},
xmin=0, xmax=600,
ymin=0, ymax=80,
xtick={0,100, 200,300,400,500,600},
ytick={0,10,20,30,40,50,60,70,80},
xtick pos=bottom,ytick pos=left,
legend pos=north west,
legend style={font=\tiny}]
\legend{-20\%, -10\%, 0\%*, +10\%, +20\%},
\addplot[color=blue1, style={line width=0.7pt},smooth]
coordinates {
(180,0)
(240,4)
(300,29)
(360,49)
(420,18)
(480,0)
};
\addplot[color=blue2,style={line width=0.8pt}, smooth]
coordinates {
(180,0)
(240,1)
(300,27)
(360,45)
(420,26)
(480,1)
(540,0)
};
\addplot[color=green,style={line width=0.9pt}, smooth]
coordinates {
(180,0)
(240,9.7)
(300,47.8)
(360,41.4)
(420,1.1)
(480,0)
};
\addplot[color=blue3,style={line width=0.9pt}, smooth]
coordinates {
(180,0)
(240,1)
(300,34)
(360,48)
(420,17)
(480,0)
};
\addplot[color=blue4,style={line width=1pt}, smooth]
coordinates {
(180,0)
(240,1)
(300,33)
(360,43)
(420,23)
(480,0)
};
\end{axis}
\end{tikzpicture}
\caption{Longevity - Risk Longevity}
\label{LongGraph8}
\end{minipage}
\end{figure}
\end{document}
答案1
您已经自己找到了解决方案(请发布答案,而不是用答案编辑您的问题,即使您的问题可能是重复的),但是既然您已经加载了subcaption
包,为什么不使用它呢?
我还缩放了你的图像,否则你会收到 Overfull hbox 警告。
\documentclass[11pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{float}
\usepackage{subcaption}
\captionsetup[figure]{justification=raggedright,
singlelinecheck=false,
format=hang,
font=small,labelfont=bf, skip=5pt} %default=10pt
\captionsetup[subfigure]{
justification=raggedright,
singlelinecheck=false,
format=hang,
belowskip=6pt,
font=small,labelfont=bf, skip=5pt
}
%Color definitions
\definecolor{green}{RGB}{0, 102, 0}
\definecolor{blue1}{RGB}{0, 125, 255}
\definecolor{blue2}{RGB}{0, 102, 204}
\definecolor{blue3}{RGB}{0, 76, 153}
\definecolor{blue4}{RGB}{0, 51, 102}
\begin{document}
\section{Bonus Potential - Side by Side}
\begin{figure}[H]\centering
\begin{subfigure}[t]{.49\linewidth}
\begin{tikzpicture}[scale=.7]
\begin{axis}[
xlabel={Bonus Potential (bn)},
ylabel={Frequency},
xmin=0, xmax=600,
ymin=0, ymax=80,
xtick={0,100, 200,300,400,500,600},
ytick={0,10,20,30,40,50,60,70,80},
xtick pos=bottom,ytick pos=left,
legend pos=north west,
legend style={font=\tiny}]
\legend{-20\%, -10\%, 0\%*, +10\%, +20\%},
\addplot[color=blue1, style={line width=0.7pt},smooth]
coordinates {
(120,0)
(180,0)
(240,39)
(300,55)
(360,6)
(420,0)
};
\addplot[color=blue2,style={line width=0.8pt}, smooth]
coordinates {
(120,0)
(180,1)
(240,30)
(300,59)
(360,9)
(420,1)
(480,0)
};
\addplot[color=green,style={line width=0.9pt}, smooth]
coordinates {
(120,0)
(180,5.8)
(240,59.8)
(300,34.2)
(360,0.2)
(420,0)
};
\addplot[color=blue3,style={line width=0.9pt}, smooth]
coordinates {
(120,0)
(180,1)
(240,31)
(300,62)
(360,6)
(420,0)
};
\addplot[color=blue4,style={line width=1pt}, smooth]
coordinates {
(120,0)
(180,1)
(240,34)
(300,52)
(360,13)
(420,0)
};
\end{axis}
\end{tikzpicture}
\caption{Minimum Variance\label{Longminvar}}
\end{subfigure}
\begin{subfigure}[t]{.49\linewidth}
\begin{tikzpicture}[scale=.7]
\begin{axis}[
xlabel={Bonus Potential (bn)},
ylabel={Frequency},
xmin=0, xmax=600,
ymin=0, ymax=80,
xtick={0,100, 200,300,400,500,600},
ytick={0,10,20,30,40,50,60,70,80},
xtick pos=bottom,ytick pos=left,
legend pos=north west,
legend style={font=\tiny}]
\legend{-20\%, -10\%, 0\%*, +10\%, +20\%},
\addplot[color=blue1, style={line width=0.7pt},smooth]
coordinates {
(180,0)
(240,4)
(300,35)
(360,51)
(420,10)
(480,0)
};
\addplot[color=blue2,style={line width=0.8pt}, smooth]
coordinates {
(180,0)
(240,1)
(300,31)
(360,49)
(420,18)
(480,1)
(540,0)
};
\addplot[color=green,style={line width=1pt}, smooth]
coordinates {
(180,0)
(240,10.5)
(300,56.4)
(360,32.5)
(420,0.6)
(480,0)
};
\addplot[color=blue3,style={line width=0.9pt}, smooth]
coordinates {
(180,0)
(240,31)
(300,53)
(360,16)
(420,0)
};
\addplot[color=blue4,style={line width=1pt}, smooth]
coordinates {
(180,0)
(240,1)
(300,33)
(360,43)
(420,23)
(480,0)
};
\end{axis}
\end{tikzpicture}
\caption{Tangency Portfolio\label{Longtangport}}
\end{subfigure}
\begin{subfigure}[t]{.49\linewidth}
\begin{tikzpicture}[scale=.7]
\begin{axis}[
xlabel={Bonus Potential (bn)},
ylabel={Frequency},
xmin=0, xmax=600,
ymin=0, ymax=80,
xtick={0,100, 200,300,400,500,600},
ytick={0,10,20,30,40,50,60,70,80},
xtick pos=bottom,ytick pos=left,
legend pos=north west,
legend style={font=\tiny}]
\legend{-20\%, -10\%, 0\%*, +10\%, +20\%},
\addplot[color=blue1, style={line width=0.7pt},smooth]
coordinates {
(180,0)
(240,31)
(300,53)
(360,16)
(420,0)
};
\addplot[color=blue2,style={line width=0.8pt}, smooth]
coordinates {
(180,0)
(240,37)
(300,45)
(360,17)
(420,1)
(480,0)
};
\addplot[color=green,style={line width=0.9pt}, smooth]
coordinates {
(120,0)
(180,3.3)
(240,50)
(300,46.3)
(360,0.4)
(420,0)
};
\addplot[color=blue3,style={line width=0.9pt}, smooth]
coordinates {
(180,0)
(240,31)
(300,53)
(360,16)
(420,0)
};
\addplot[color=blue4,style={line width=1pt}, smooth]
coordinates {
(180,0)
(240,29)
(300,55)
(360,16)
(420,0)
};
\end{axis}
\end{tikzpicture}
\caption{Sortino\label{Longsort}}
\end{subfigure}
\begin{subfigure}[t]{.49\linewidth}
\begin{tikzpicture}[scale=.7]
\begin{axis}[
xlabel={Bonus Potential (bn)},
ylabel={Frequency},
xmin=0, xmax=600,
ymin=0, ymax=80,
xtick={0,100, 200,300,400,500,600},
ytick={0,10,20,30,40,50,60,70,80},
xtick pos=bottom,ytick pos=left,
legend pos=north west,
legend style={font=\tiny}]
\legend{-20\%, -10\%, 0\%*, +10\%, +20\%},
\addplot[color=blue1, style={line width=0.7pt},smooth]
coordinates {
(180,0)
(240,4)
(300,29)
(360,49)
(420,18)
(480,0)
};
\addplot[color=blue2,style={line width=0.8pt}, smooth]
coordinates {
(180,0)
(240,1)
(300,27)
(360,45)
(420,26)
(480,1)
(540,0)
};
\addplot[color=green,style={line width=0.9pt}, smooth]
coordinates {
(180,0)
(240,9.7)
(300,47.8)
(360,41.4)
(420,1.1)
(480,0)
};
\addplot[color=blue3,style={line width=0.9pt}, smooth]
coordinates {
(180,0)
(240,1)
(300,34)
(360,48)
(420,17)
(480,0)
};
\addplot[color=blue4,style={line width=1pt}, smooth]
coordinates {
(180,0)
(240,1)
(300,33)
(360,43)
(420,23)
(480,0)
};
\end{axis}
\end{tikzpicture}
\caption{Risk Longevity\label{Longrisk}}
\end{subfigure}
\caption{Longevity\label{Long}}
\end{figure}
\end{document}