防止圖形標題中的換行

防止圖形標題中的換行

我有下圖和對應的標題:在此輸入影像描述

正如你所看到的,標題不恰當地打破了界限,這是我想避免的。最好不要簡單地減少標題文字的字體大小。

程式碼如下:

\documentclass[12pt, a4paper] {article}
\usepackage[skip=10pt, labelfont=bf, labelsep=space]{caption}
\usepackage{tikz}
\usepackage[numbers,sort,authoryear]{natbib}
\hypersetup{hidelinks=true}


\begin{document}

\newcommand{\mytab}[1]{%
\begin{tabular}{@{}c@{}}
#1
\end{tabular}
}
\begin{figure} [h!]
\label{fig: timeline}
\begin{center}
\begin{tikzpicture}
\draw (0,0) -- (11,0);
\foreach \x in {0.8,4,5.5,7,10.2}
\draw(\x cm,3pt) -- (\x cm, -3pt);
\draw (0.8,0) node[below=3pt] {$T_0$};
\draw (4,0) node[below=3pt] {$T_1$};
\draw (5.5,0) node[below=3pt] {$0$};
\draw (7,0) node[below=3pt] {$T_2$};
\draw (10.2,0) node[below=3pt] {$T_3$};
\draw (2.35,0) node[above=12pt, align=center] {
                            $\left(\mytab{estimation \\ window}\right]$};
\draw (5.5,0) node[above=12pt, align=center]{
                            $\left(\mytab{event \\ window}\right]$};
\draw(8.65,0) node[above=12pt, align=center]{
                            $\left(\mytab{post-event \\ window}\right]$};
\end{tikzpicture}
\end{center}
\caption{Time Line for an Event Study (\cite{campbell1996}, p. 157})
\end{figure}

\bibliographystyle{agsm}
\bibliography{./references}
\end{document}

感謝您的幫忙!

答案1

幾點評論:

  • 由於您 (i) 使用agsm參考書目樣式,該樣式與引文管理包一起分發harvard,並且 (ii) 加載natbib包而不是包,因此您也harvard應該加載包。har2nat如其名稱所示,它將套件定義的各種巨集harvard(以及在 中使用的巨集agsm.bst)「翻譯」為等效的natbib巨集。

  • 您目前正在載入natbib帶有選項numberssort和 的套件authoryear。您應該放棄前兩個選項: 此agsm樣式適用於作者年份樣式的引文標註 - 嘗試將其與數字樣式的引文標註一起使用毫無意義;此選項僅在標註樣式sort時才有意義。numbers

  • 現在到您的查詢的要點:您應該將\caption命令寫為

    \caption{Time Line for an Event Study \citep[p.~157]{campbell1996}}
    

    請注意(“tie”)字元的使用~,它的作用類似於牢不可破的空格字元。

  • 兩個小要點: (i)\label指示應該到來說明\caption- 特別是如果您希望能夠交叉引用文件中其他位置的圖。 (ii) 使用\begin{center}...\end{center}會增加大量(垂直)空白;請改用該\centering指令。

在此輸入影像描述

\documentclass[12pt, a4paper]{article}
\usepackage{filecontents}
\begin{filecontents}{references.bib}
@book{campbell1996,
  author = "John Y. Campbell and Andrew W. Lo and A. Craig McKinlay",
  title  = "The Econometrics of Financial Markets",
  year   = 1996,
  publisher = "Princeton University Press",
  address = "Princeton NJ",
}
\end{filecontents}
\usepackage[skip=10pt, labelfont=bf, labelsep=space]{caption}
\usepackage{tikz}
\usepackage[authoryear]{natbib}
\usepackage{har2nat}
\usepackage{hyperref}
\hypersetup{hidelinks=true}

\newcommand{\mytab}[1]{%
\begin{tabular}{@{}c@{}}
#1
\end{tabular}
}

\begin{document}

\begin{figure} [h!]
\centering
\begin{tikzpicture}
\draw (0,0) -- (11,0);
\foreach \x in {0.8,4,5.5,7,10.2}
\draw(\x cm,3pt) -- (\x cm, -3pt);
\draw (0.8,0) node[below=3pt] {$T_0$};
\draw (4,0) node[below=3pt] {$T_1$};
\draw (5.5,0) node[below=3pt] {$0$};
\draw (7,0) node[below=3pt] {$T_2$};
\draw (10.2,0) node[below=3pt] {$T_3$};
\draw (2.35,0) node[above=12pt, align=center] {
                            $\left(\mytab{estimation \\ window}\right]$};
\draw (5.5,0) node[above=12pt, align=center]{
                            $\left(\mytab{event \\ window}\right]$};
\draw(8.65,0) node[above=12pt, align=center]{
                            $\left(\mytab{post-event \\ window}\right]$};
\end{tikzpicture}
\caption{Time Line for an Event Study \protect\citep[p.~157]{campbell1996}} 
\label{fig:timeline}
\end{figure}

A cross-reference to \autoref{fig:timeline}.

\bibliographystyle{agsm}
\bibliography{./references}
\end{document}

相關內容