Sphinxのsphinxcontrib-plantuml
やsphinx.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}
}
'''