From b471931a82c89a7c7988144058cb0d3ca5383317 Mon Sep 17 00:00:00 2001 From: Niclas Date: Mon, 26 Dec 2022 00:59:19 +0100 Subject: [PATCH 1/2] Adjust recalculated figure size based on ratio instead of difference This solves issues with pgfplots' groupplot environments that lead to negative widths/heights while iteratively searching for the correct scaling factor. --- .gitignore | 22 ++++++++++++++++++++++ groupplot.tikz | 26 ++++++++++++++++++++++++++ test-tikzscale.tex | 6 ++++++ tikzscale.dtx | 8 ++++---- 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 groupplot.tikz diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..32edae4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ + +*.dpth + +*.log + +*.md5 + +*.pdf + +*.dep + +*.aux + +*.auxlock + +test-tikzscale.synctex.gz + +*.ins + +*.sty + +README.txt diff --git a/groupplot.tikz b/groupplot.tikz new file mode 100644 index 0000000..e623a58 --- /dev/null +++ b/groupplot.tikz @@ -0,0 +1,26 @@ +\begin{tikzpicture} + \begin{groupplot}[ + group style={ + group size=2 by 2, + y descriptions at=edge left, + x descriptions at=edge bottom + }, + xlabel=$x$, + ylabel=$y$ + ] + + \nextgroupplot + \addplot {x^2 - x + 4}; + + \nextgroupplot + \addplot {x^2 - x + 4}; + + \nextgroupplot + \addplot {x^2 - x + 4}; + + \nextgroupplot + \addplot {x^2 - x + 4}; + + \end{groupplot} + +\end{tikzpicture} \ No newline at end of file diff --git a/test-tikzscale.tex b/test-tikzscale.tex index b95cceb..fc76aca 100644 --- a/test-tikzscale.tex +++ b/test-tikzscale.tex @@ -57,6 +57,12 @@ \includegraphics{pgfplots-test}% \item Use pgfplots with given width and height\\% \includegraphics[width=\linewidth,height=0.3\linewidth]{pgfplots-test}% + \item Use pgfplots with a 2x2 groupplot with a given total width\\% + \includegraphics[width=\linewidth]{groupplot} + \item Use pgfplots with a 2x2 groupplot with given total width and height\\% + \includegraphics[width=\linewidth,height=0.5\linewidth]{groupplot} + \item Use pgfplots with a 2x2 groupplot with given total width and axis ratio\\% + \includegraphics[width=\linewidth,axisratio=0.5]{groupplot} \item Use includegraphics with only a node\\% \includegraphics{testNode.tikz}% % \item Use includegraphics with scaling only a node results in an error\\% diff --git a/tikzscale.dtx b/tikzscale.dtx index dd61f5f..02edce6 100644 --- a/tikzscale.dtx +++ b/tikzscale.dtx @@ -1583,8 +1583,8 @@ and the derived files tikzscale.ins, % \end{macrocode} % Correct the dimension by the error. Use a global assignment, as each iteration in the loop is put into a separate group. % \begin{macrocode} - \pgfmathsetglobalmacro{\tikzscale@width}{\tikzscale@width - \widthDifference}% - \pgfmathsetglobalmacro{\tikzscale@height}{\tikzscale@height - \heightDifference}% + \pgfmathsetglobalmacro{\tikzscale@width}{\requestedWidth / \wd\tikzscale@measuredSize * \tikzscale@width}% + \pgfmathsetglobalmacro{\tikzscale@height}{\requestedHeight / \ht\tikzscale@measuredSize * \tikzscale@height}% }{% \breakforeach }% @@ -1644,10 +1644,10 @@ and the derived files tikzscale.ins, % \begin{macrocode} \tikzscale@ifSizeDifference{\sizeDifference}{% \tikzscale@ifIsWidth{#1}{% - \pgfmathsetglobalmacro{\tikzscale@width}{\tikzscale@width - \sizeDifference}% + \pgfmathsetglobalmacro{\tikzscale@width}{\requestedSize / \measuredSize * \tikzscale@width}% \pgfmathsetglobalmacro{\tikzscale@height}{\tikzscale@width / \requestedAxisRatio}% }{% - \pgfmathsetglobalmacro{\tikzscale@height}{\tikzscale@height - \sizeDifference}% + \pgfmathsetglobalmacro{\tikzscale@height}{\requestedSize / \measuredSize * \tikzscale@height}% \pgfmathsetglobalmacro{\tikzscale@width}{\tikzscale@height * \requestedAxisRatio}% }% \tikzscale@ifSizeDifference{\sizeDifference-\tikzscale@oldSizeDifference}{% From 09e188b9272ff351f6c95808c14c2f2df36464a5 Mon Sep 17 00:00:00 2001 From: daharn <44439108+daharn@users.noreply.github.com> Date: Mon, 9 Jan 2023 10:18:39 +0100 Subject: [PATCH 2/2] Forgot groupplots library in test-tikzscale --- test-tikzscale.tex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test-tikzscale.tex b/test-tikzscale.tex index fc76aca..1db1b1b 100644 --- a/test-tikzscale.tex +++ b/test-tikzscale.tex @@ -6,6 +6,7 @@ \usepackage{pgfplots} \usepackage{tikz-3dplot} \usetikzlibrary{backgrounds} +\usepgfplotslibrary{groupplots} \usepackage{currfile} \usepackage{lmodern} % Use the package subcaption to test the subfigure command @@ -127,4 +128,4 @@ \end{subfigure} \end{figure} -\end{document} \ No newline at end of file +\end{document}