3

Is there anything like

\pgfplotsset{
every axis/.append style={
width = 0.9\linewidth, 
max width = 4in
}}

Suppose I have a document with hundreds of tikzpicture environments, each having plots that use pgfplots axis environments. For simplicity of my question, none are in floats. Half of these appear individually as their own "paragraph". Half of them appear inside narrow environments, such as side by side minipages.

I'd like to use something like width = 0.9\linewidth, except that this would make the images which appear in their own paragraphs much too wide. So I'd like to put an upper bound on the width. Doesn't look like max width works as a key for this.

I am hoping to avoid setting width locally in any of the images.

3

You could use

width = {ifthenelse(.9\linewidth>3in,3in,.9\linewidth)}

Example:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{
  compat=1.13,
  every axis/.append style={
    width = {ifthenelse(.9\linewidth>3in,3in,.9\linewidth)}
  }
}

\begin{document}
\begin{tikzpicture}
  \begin{axis}
  \addplot{x};
  \end{axis}
\end{tikzpicture}

\begin{minipage}[b]{5cm}
\begin{tikzpicture}
  \begin{axis}
  \addplot{x};
  \end{axis}
\end{tikzpicture}
\end{minipage}
\end{document}

enter image description here

  • Thanks, I never would have thought that you could define width could dynamically this way. – alex.jordan Jul 17 '16 at 23:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.