# pgfplots: Accessing the Width of a Diagram and Using it as a Variable for other Widths

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

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

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
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}}]