我想知道是否有办法在 tikzfigure 上方稍微制作一个矩形框,用于标记目的?我已经演示了我认为它应该是什么样的,如下所示:
其中带有 EV/EBIT 的深灰色框是我想要创建的框。显然,为了看起来美观,它应该具有与图完全相同的宽度。我在图表中使用以下代码:
\documentclass{article}
\usepackage{pgfplots, pgfplotstable}
\usepackage{tikz}
\begin{document}
\begin{figure}[h]
\caption{Time series median of APE for the EV/EBIT multiple based on combinatorial selection schemes}
\label{Figure.TimeseriesofAPE}
\centering
\begin{tikzpicture}
\begin{axis}[width=14cm,height=8cm,
ylabel={Absolute Percentage Error},
xmin=2003.5,
xmax=2018.5,
ymin=15,
ymax=35,
xtick=data,
xticklabel style=
{/pgf/number format/1000 sep=,rotate=40},
ytick={15, 20, 25, 30, 35},
axis background/.style={fill=gray!5},
legend style={fill=gray!5},
xtick pos=lower,ytick pos=left,
yticklabel=\pgfkeys{/pgf/number format/.cd,fixed,precision=0,zerofill}\pgfmathprintnumber{\tick}\%,
]
\addplot [semithick,mark=square*,blue,mark options={scale=1.2}] coordinates {
(2004,23.9477345892197)
(2005,24.0195465335992)
(2006,20.6276481251735)
(2007,18.265284388086)
(2008,21.8111180034732)
(2009,24.2629967323528)
(2010,22.2193898469998)
(2011,23.4662001690915)
(2012,22.3983479598189)
(2013,21.6518435739983)
(2014,20.7295962241899)
(2015,21.5151016657556)
(2016,22.728213671688)
(2017,20.6614535846647)
(2018,23.2079687708666)
};
\addlegendentry{SBP Plus SARD}
\addplot[semithick,mark=*,red,mark options={scale=1.2}]
coordinates{
(2004,30.6453384436133)
(2005,25.9071572285215)
(2006,21.5368656549373)
(2007,23.1619489291921)
(2008,22.716278332465)
(2009,26.6295451295127)
(2010,25.7656563953101)
(2011,21.0579081996823)
(2012,23.9734983213042)
(2013,27.0328903793312)
(2014,23.5204904251705)
(2015,24.5540581415406)
(2016,27.393772936285)
(2017,23.77644107908)
(2018,24.9426613487672)
};
\addlegendentry{GICS Plus SARD}
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
答案1
pgfplots
有title
这个密钥:
\documentclass{article}
\usepackage{pgfplots, pgfplotstable}
\usepackage{tikz}
\begin{document}
\begin{figure}[h]
\caption{Time series median of APE for the EV/EBIT multiple based on combinatorial selection schemes}
\label{Figure.TimeseriesofAPE}
\centering
\begin{tikzpicture}
\begin{axis}[width=14cm,height=8cm,
ylabel={Absolute Percentage Error},
xmin=2003.5,
xmax=2018.5,
ymin=15,
ymax=35,
xtick=data,
xticklabel style=
{/pgf/number format/1000 sep=,rotate=40},
ytick={15, 20, 25, 30, 35},
axis background/.style={fill=gray!5},
legend style={fill=gray!5},
xtick pos=lower,ytick pos=left,
yticklabel=\pgfkeys{/pgf/number format/.cd,fixed,precision=0,zerofill}\pgfmathprintnumber{\tick}\%,
title=\fcolorbox{black}{gray!50!white}{\makebox[12.17cm]{EV/EBIT}},
title style={yshift=-0.33cm},
]
\addplot [semithick,mark=square*,blue,mark options={scale=1.2}] coordinates {
(2004,23.9477345892197)
(2005,24.0195465335992)
(2006,20.6276481251735)
(2007,18.265284388086)
(2008,21.8111180034732)
(2009,24.2629967323528)
(2010,22.2193898469998)
(2011,23.4662001690915)
(2012,22.3983479598189)
(2013,21.6518435739983)
(2014,20.7295962241899)
(2015,21.5151016657556)
(2016,22.728213671688)
(2017,20.6614535846647)
(2018,23.2079687708666)
};
\addlegendentry{SBP Plus SARD}
\addplot[semithick,mark=*,red,mark options={scale=1.2}]
coordinates{
(2004,30.6453384436133)
(2005,25.9071572285215)
(2006,21.5368656549373)
(2007,23.1619489291921)
(2008,22.716278332465)
(2009,26.6295451295127)
(2010,25.7656563953101)
(2011,21.0579081996823)
(2012,23.9734983213042)
(2013,27.0328903793312)
(2014,23.5204904251705)
(2015,24.5540581415406)
(2016,27.393772936285)
(2017,23.77644107908)
(2018,24.9426613487672)
};
\addlegendentry{GICS Plus SARD}
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
答案2
最好用蒂克兹通过添加title style
规范来生产:
这是您修改后的 MWE。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{figure}[h]
\caption{Time series median of APE based on combinatorial selection schemes}
\label{Figure.TimeseriesofAPE}
\centering
\begin{tikzpicture}
\begin{axis}[width=14cm,height=8cm,
ylabel={Absolute Percentage Error},
xmin=2003.5,
xmax=2018.5,
ymin=15,
ymax=35,
xtick=data,
xticklabel style=
{/pgf/number format/1000 sep=,rotate=40},
ytick={15, 20, 25, 30, 35},
axis background/.style={fill=gray!5},
legend style={fill=gray!5},
xtick pos=lower,ytick pos=left,
yticklabel=\pgfkeys{/pgf/number format/.cd,fixed,precision=0,zerofill}\pgfmathprintnumber{\tick}\%,
title={\textbf{EV/EBIT}},
title style={yshift=-2.2mm,fill={rgb:red,0;green,48;blue,133},
text=white,rectangle, minimum width=124.5mm},
]
\addplot [semithick,mark=square*,black,mark options={scale=1.2}] coordinates {
(2004,23.9477345892197)
(2005,24.0195465335992)
(2006,20.6276481251735)
(2007,18.265284388086)
(2008,21.8111180034732)
(2009,24.2629967323528)
(2010,22.2193898469998)
(2011,23.4662001690915)
(2012,22.3983479598189)
(2013,21.6518435739983)
(2014,20.7295962241899)
(2015,21.5151016657556)
(2016,22.728213671688)
(2017,20.6614535846647)
(2018,23.2079687708666)
};
\addlegendentry{SBP Plus SARD}
\addplot[semithick,mark=*,red,mark options={scale=1.2}]
coordinates{
(2004,30.6453384436133)
(2005,25.9071572285215)
(2006,21.5368656549373)
(2007,23.1619489291921)
(2008,22.716278332465)
(2009,26.6295451295127)
(2010,25.7656563953101)
(2011,21.0579081996823)
(2012,23.9734983213042)
(2013,27.0328903793312)
(2014,23.5204904251705)
(2015,24.5540581415406)
(2016,27.393772936285)
(2017,23.77644107908)
(2018,24.9426613487672)
};
\addlegendentry{GICS Plus SARD}
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}