Adjustbox reduziert die Breite von Tabellen und Tikzbildern nicht

Adjustbox reduziert die Breite von Tabellen und Tikzbildern nicht

Ich gestalte Vorlesungsunterlagen für einen Universitätskurs neu, da die Studenten die Unterlagen auf ihren Tablets, E-Book-Readern usw. lesen wollten. Daher habe ich ein Makefile mit unterschiedlichen Zielen für unterschiedliche Seitengrößen geschrieben. Das einzige Problem, das ich habe, sind einige PGF/TikZ-Abbildungen und einige Tabellen, die zu groß sind, um auf ein kleines Blatt Papier zu passen.

Ich möchte verwendenadjustboxum die Größe von in PGF/TikZ gezeichneten Tabellen und Abbildungen zu reduzieren, wenn sie zu groß für das definierte Papierformat sind. Das funktioniert allerdings nicht wirklich.

\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}

mwe

Die Frage ist also, was übersehe ich oder mache ich falsch? Gibt es einen anderen Ansatz zum Verkleinern von Tabellen und Abbildungen, wenn sie nicht auf ein kleines Papierformat passen?

Antwort1

Es gibt zwei Probleme. Das erste ist, dass Sie die Werte von \maxtabfigwidthund \maxtabfigheightspäter berechnen müssen, da geometrydie Berechnungen am Anfang des Dokuments erfolgen.

Das zweite Problem ist, dass die Reihenfolge der Optionen bis adjustboxvon Bedeutung ist. Insbesondere müssen sie nach und centerkommen .max widthmax 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}

Bildbeschreibung hier eingeben

verwandte Informationen