I define the width of a plot/diagram using the width key, for example:

width = 0.8\textwidth,

I also define the width of the title text similar:

title style = {text width = 0.7\textwidth},

I am looking for a way to use the diagramm width as a variable in the definition of the text width in the title style. Here is my "pseudo code wish":

title style = {text width = 0.9\myPlotwidth},

In this case \myPlotwidth (which I inventetd, the key does not exist) would in this case/example be 0.8\textwidth.

Is there a key like \myPlotwidth?

  • Is defining a new length and using that an option? \newlength\myplotwidth\setlength{\myplotwidth}{0.8\textwidth} and then use text width=0.9\myplotwidth. – Torbjørn T. Nov 2 '15 at 15:45
  • @TorbjørnT. This is a fallback solution for me. I already use this approach for figures and subfigures. I am just wondering if the plot width is accessible. Thanks for your suggestion. – Dr. Manuel Kuehner Nov 2 '15 at 15:47

Looks like using \pgfkeysvalueof{/pgfplots/width} works.

In general, if you look in the manual you will see in the description of a key something like

enter image description here

The value of the key can then be retrieved with \pgfkeysvalueof{/pgfplots/width}.

enter image description here

width = 0.8\textwidth,
title={Some text and more text to make a long title that will break},
title style={text width=0.7*\pgfkeysvalueof{/pgfplots/width}}]
\node [align=left] at (rel axis cs:0.5,0.5) {
 Textwidth = \the\textwidth,\\
 Axis width = \pgfkeysvalueof{/pgfplots/width}};
| improve this answer | |
  • Damn, I get ! Illegal unit of measure (pt inserted). – Dr. Manuel Kuehner Nov 2 '15 at 15:56
  • My mistake: I need to use the multiplicator symbol *! I don't need that in 0.9\textwidth but I need it in 0.9*\pgfkeysvalueof{/pgfplots/width}. – Dr. Manuel Kuehner Nov 2 '15 at 15:57
  • Perfect answer - great! – Dr. Manuel Kuehner Nov 2 '15 at 15:59
  • 1
    @Dr.ManuelKuehner I made the same mistake at first, until I realized that the value retrieved probably isn't a length in the TeX sense, so that won't work. Luckily calculations are allowed in cases like that. – Torbjørn T. Nov 2 '15 at 16:00

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.