![Adjustboxはテーブルとtikzpictureの幅を縮小しません](https://rvso.com/image/281580/Adjustbox%E3%81%AF%E3%83%86%E3%83%BC%E3%83%96%E3%83%AB%E3%81%A8tikzpicture%E3%81%AE%E5%B9%85%E3%82%92%E7%B8%AE%E5%B0%8F%E3%81%97%E3%81%BE%E3%81%9B%E3%82%93.png)
学生がタブレットや電子書籍リーダーなどでノートを読みたいと望んでいるため、大学の授業の講義ノートを再設計しています。そこで、ページ サイズごとに異なるターゲットを持つ Makefile を作成しました。唯一の問題は、一部の PGF/TikZ 図と一部の表が大きすぎて小さな用紙サイズに収まらないことです。
使用したいadjustbox
PGF/TikZ で描画された表や図が大きすぎて定義された用紙サイズに収まらない場合に、そのサイズを縮小します。ただし、実際には機能しません。
\documentclass[10pt]{article}
% set page size with geometry
\usepackage[nohead,%
nofoot,%
nomarginpar,%
paperwidth=106.68mm,%
paperheight=142.24mm,%
tmargin=2.5mm,%
rmargin=2.5mm,%
bmargin=2.5mm,%
lmargin=2.5mm]{geometry}
\usepackage{float}
\usepackage{tikz}
\usepackage{adjustbox}
%define lengths for maximum figure and table width and height
\newlength{\maxtabfigwidth}
\newlength{\maxtabfigheight}
\setlength{\maxtabfigwidth}{\textwidth}
\setlength{\maxtabfigheight}{\textheight}
% decrease height a bit letting captions fit to one page
\addtolength{\maxtabfigheight}{-2.5em}
\pagestyle{empty}
\begin{document}
\section*{Example \#1}
The width of the table isn't reduced to \texttt{\textbackslash{}maxtabfigwidth}.
\begin{adjustbox}{center,%
max width={\maxtabfigwidth},%
max totalheight={\maxtabfigheight},%
captionbelow={A wide table},%
float={table}[h!]}
\begin{tabular}{p{6cm}p{6cm}}
\hline
wide & table \\\hline
\end{tabular}
\end{adjustbox}
\section*{Example \#2}
The width of the tikzpicture isn't reduced to \texttt{\textbackslash{}maxtabfigwidth}.
\begin{adjustbox}{center,%
max width={\maxtabfigwidth},%
max totalheight={\maxtabfigheight},%
captionbelow={A wide tikzpicture},%
float={figure}[H]}
\begin{tikzpicture}
\fill[black] (0cm, 0cm) -- (0cm, -3cm) -- (12cm, -3cm) -- (12cm, 0cm) -- cycle;
\end{tikzpicture}
\end{adjustbox}
\section*{Example \#3}
The height of the tikzpicture is reduced to\texttt{\textbackslash{}maxtabfigheight}, however it is not centered.
\begin{adjustbox}{center,%
max width={\maxtabfigwidth},%
max totalheight={\maxtabfigheight},%
captionbelow={A tall tikzpicture},%
float={figure}[H]}
\begin{tikzpicture}
\fill[black] (0cm, 0cm) -- (0cm, -15cm) -- (5cm, -15cm) -- (5cm, 0cm) -- cycle;
\end{tikzpicture}
\end{adjustbox}
\end{document}
では、何が足りないのか、あるいは何が間違っているのか、という疑問が湧きます。表や図が小さい用紙サイズに収まらない場合、縮小する他の方法はありますか?
答え1
問題が 2 つあります。1 つ目は、ドキュメントの開始時に の計算が行われるため、\maxtabfigwidth
との値を\maxtabfigheight
後で計算する必要があることです。geometry
2 番目の問題は、オプションの順序adjustbox
が重要であることです。特に、はcenter
と の後に来なければなりません。max width
max totalheight
\documentclass[10pt]{article}
% set page size with geometry
\usepackage[nohead,%
nofoot,%
nomarginpar,%
paperwidth=106.68mm,%
paperheight=142.24mm,%
tmargin=2.5mm,%
rmargin=2.5mm,%
bmargin=2.5mm,%
lmargin=2.5mm]{geometry}
\usepackage{float}
\usepackage{tikz}
\usepackage{adjustbox}
%define lengths for maximum figure and table width and height
\newlength{\maxtabfigwidth}
\newlength{\maxtabfigheight}
\AtBeginDocument{
\setlength{\maxtabfigwidth}{\textwidth}
\setlength{\maxtabfigheight}{\textheight}
% decrease height a bit letting captions fit to one page
\addtolength{\maxtabfigheight}{-2.5em}
}
\pagestyle{empty}
\begin{document}
\section*{Example \#1}
The width of the table isn't reduced to \texttt{\textbackslash{}maxtabfigwidth}.
\begin{adjustbox}{
max width=\maxtabfigwidth,
max totalheight=\maxtabfigheight,
center,
captionbelow={A wide table},
float={table}[h!],
}
\begin{tabular}{p{6cm}p{6cm}}
\hline
wide & table \\\hline
\end{tabular}
\end{adjustbox}
\section*{Example \#2}
The width of the tikzpicture isn't reduced to \texttt{\textbackslash{}maxtabfigwidth}.
\begin{adjustbox}{
max width=\maxtabfigwidth,
max totalheight=\maxtabfigheight,
center,
captionbelow={A wide tikzpicture},%
float={figure}[H],
}
\begin{tikzpicture}
\fill[black] (0cm, 0cm) -- (0cm, -3cm) -- (12cm, -3cm) -- (12cm, 0cm) -- cycle;
\end{tikzpicture}
\end{adjustbox}
\section*{Example \#3}
The height of the tikzpicture is reduced to\texttt{\textbackslash{}maxtabfigheight}, however
it is not centered.
\begin{adjustbox}{
max width=\maxtabfigwidth,
max totalheight=\maxtabfigheight,
center,
captionbelow={A tall tikzpicture},
float={figure}[H],
}
\begin{tikzpicture}
\fill[black] (0cm, 0cm) -- (0cm, -15cm) -- (5cm, -15cm) -- (5cm, 0cm) -- cycle;
\end{tikzpicture}
\end{adjustbox}
\end{document}