2

Is there a simple way of making a common x-axis label?

I have referred to this: Common x-axis label in different rows of pgfplots mult

and the solution appears very complex and doesn't work for me.

Here is a my MWE:

\documentclass{standalone}
\usepackage{siunitx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepackage[sfdefault]{atkinson}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel={Work},
ylabel={Effort},
title={Graphpart 1}]
\addplot[no marks]{x^2+x+2};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[xlabel={Work},
ylabel={Effort},
title={Graphpart 2}]
\addplot[only marks, red, mark size=1pt]{x^3+x+2};
\end{axis}
\end{tikzpicture}
\end{document}

Which produces this output: Test_image

I would like Work to be in the centre as the common x-axis label.

Peter Grill
  • 223,288
Miloop
  • 783

1 Answers1

1

You really should use a groupplot. But, for now you can use a slightly hackish method and that is to use xlabel style to position the xlabel:

xlabel style = {
    at={(ticklabel cs:0)},
    anchor=north east,
    xshift=-0.35cm,
},

A \vphantom{} was applied to the first graph's xlabel to ensure that the x-axis was located at the same spot vertically.

enter image description here

Code:

\documentclass{article}
\usepackage{siunitx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepackage[sfdefault]{atkinson}

\begin{document} \noindent \begin{tikzpicture} \begin{axis}[ xlabel={\vphantom{Work}}, ylabel={Effort}, title={Graphpart 1}] \addplot[no marks]{x^2+x+2}; \end{axis} \end{tikzpicture} \begin{tikzpicture} \begin{axis}[xlabel={Work}, ylabel={Effort}, title={Graphpart 2}, xlabel style = { at={(ticklabel cs:0)}, anchor=north east, xshift=-0.35cm, }, ] \addplot[only marks, red, mark size=1pt]{x^3+x+2}; \end{axis} \end{tikzpicture}% \end{document}

Peter Grill
  • 223,288