LoginSignup
8
9

More than 5 years have passed since last update.

Sphinx(latex→PDF)で図がはみ出さないようにする方法

Posted at

Sphinxのsphinxcontrib-plantumlsphinx.ext.graphvizを使って図を書いていたら、すごく縦長になってページの下にはみ出てしまう。

この場合、下記の対処をするとうまく行った。

  • adjustboxを使って、はみ出しそうな場合にはリサイズする。
  • ページいっぱいになってしまう場合は、自動的に別ページに逃がせるよう、figureを使う。

プリアンブルをconf.pyに追記しておけば、どんな図でも同じように対応できる。

conf.py
# 末尾に追加

latex_elements['preamble'] = r'''
\usepackage[export]{adjustbox}
\usepackage{letltxmacro}
\LetLtxMacro{\origincludegraphics}{\includegraphics}
\renewcommand*\includegraphics[2][max width=\textwidth,max height=\textheight,keepaspectratio]{%
\begin{figure}[htbp]
\origincludegraphics[#1]{#2}
\end{figure}
}
'''
8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9