0

I have two tikz figures I want to place next to each other using a mini page environment. However, I noticed that something is wrong with defining the height and width of my tikz figure using \setlength inside the mini page, since the size of the tikz plot somehow doesn't change... Putting \setlength inside the tikzpicture environment is no option, as I want to import the tikz plot using \input command.

Here is a MWE:

\begin{document}
\newlength\pgfplotswidth


\begin{figure}
\begin{minipage}[b]{\textwidth}
{
\setlength\pgfplotswidth{.1\textwidth}
\begin{tikzpicture}
\begin{axis}[
    width=\pgfplotswidth,
    height=\pgfplotswidth,
]
\end{axis}
\end{tikzpicture}}
\end{minipage}
\end{figure}
\end{document}
3
  • 2
    Where do you load the tikz package? Can you please add a screenshot to your question, if the problem remains?
    – MS-SPO
    Feb 8, 2023 at 12:24
  • Welcome to TeX.SX! A tip: You can use backticks ` to mark your inline code as I did in my edit.
    – dexteritas
    Feb 8, 2023 at 15:04
  • The problem is in pgfplots. Specifically, the width and height include the ticks, labels, titles etc. and are really estimates. scale only axis is better to control the box, and axis equal will make circles etc. appear normal. Feb 8, 2023 at 16:10

1 Answer 1

2

I added a minimal preamble (ideally, your MWE should include it) and tried your code in Overleaf. It works just fine for lengths larger than 0.1\textwidth. It even works when invoking the tikz object through \input. If you still have the issue, please share more details about your setup (latex distribution, compiler).

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
\newlength\pgfplotswidth

\begin{figure}
\begin{minipage}[b]{\textwidth}
{
    \setlength\pgfplotswidth{.5\textwidth}
    \begin{tikzpicture}
    \begin{axis}[
        width=\pgfplotswidth,
        height=\pgfplotswidth,
    ]
    \end{axis}
    \end{tikzpicture}
} {
    \setlength\pgfplotswidth{.3\textwidth}
    \begin{tikzpicture}
    \begin{axis}[
        width=\pgfplotswidth,
        height=\pgfplotswidth,
    ]
    \end{axis}
    \end{tikzpicture}
}
\end{minipage}
\end{figure}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .