![Ajustarbox no reduce el ancho de la tabla y de la imagen tikz](https://rvso.com/image/281580/Ajustarbox%20no%20reduce%20el%20ancho%20de%20la%20tabla%20y%20de%20la%20imagen%20tikz.png)
Estoy rediseñando notas de clase para una clase universitaria ya que los estudiantes querían leer las notas en sus tabletas, lectores de libros electrónicos, etc. Así que escribí un Makefile con diferentes objetivos para diferentes tamaños de página. El único problema que tengo es con algunas figuras de PGF/TikZ y algunas tablas que son demasiado grandes para caber en un tamaño de papel pequeño.
me gustaría usaradjustbox
para reducir el tamaño de las tablas y figuras dibujadas en PGF/TikZ, si son demasiado grandes para caber en el tamaño de papel definido. Sin embargo, en realidad no funciona.
\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}
Entonces la pregunta es ¿qué me estoy perdiendo o qué estoy haciendo mal? ¿Existe algún otro método para reducir tablas y figuras si no caben en un tamaño de papel pequeño?
Respuesta1
Hay dos problemas. La primera es que necesita calcular los valores de \maxtabfigwidth
y \maxtabfigheight
más tarde, porque geometry
sus cálculos comienzan al documento.
El segundo problema es que el orden de las opciones adjustbox
es significativo. En particular center
hay que ir tras max width
y 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}