1

does anyone knows how to remove the white space below the x-label and left of the y-label in pgfplots? (Not the space between ticks and labels - this is not a problem for me)

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
            xlabel={test label x},
            ylabel={test label y},
            every label/.style={fill=none,inner sep=-10pt}
            ]
\addplot+[mark=none]{x^2)};
\end{axis}
\end{tikzpicture}
\end{document}

Thanks a lot!

3
  • Welcome to TeX.SX! Could you add an image with the result of your code and draw on that which white space you want to have removed? Because I don't know were the white space should be ... :( Dec 3, 2021 at 17:54
  • 1
    hm, test if this: \documentclass{standalone} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[ xlabel={test label x}, ylabel={test label y}, ylabel style={at={(1.5em,0.5)}, inner sep=0pt}, xlabel style={at={(0.5,0.5ex)}, inner sep=0pt}, ] \addplot+[mark=none]{x^2)}; \end{axis} \end{tikzpicture} \end{document} gives what you after.
    – Zarko
    Dec 3, 2021 at 18:30
  • Thanks Zarko, this is a nice approach! But if i understand this correct, i have to adjust the label postion everytime when i produce a plot with different width/height ? With compat=1.18 the label postion is inside the plot - so it has to be adjusted. But nevertheless a first solution to my problem! Thanks
    – Ben
    Dec 4, 2021 at 17:18

2 Answers 2

0
\documentclass[border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel={test label x},
ylabel={test label y},
xlabel near ticks,
ylabel near ticks,
%label style={inner sep=0pt}, %even less space
%tick label style={inner sep=0pt}, %even less space
]
\addplot[blue]{x^2)};
\end{axis}
\end{tikzpicture}
\end{document}

Graph with less space around labels

1
  • Yes thanks - without the "border=1cm" and with "the label style={inner sep=0pt}" it is exactly what I had in mind! Problem solved.
    – Ben
    Dec 4, 2021 at 17:34
0

Could you add an image with the result of your code and draw on that which white space you want to have removed? Because I don't know were the white space should be ... :(

Sorry, I'll add a picture .. It's the first time I've posted a problem on this forum;D

The code:

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
            xlabel={test label x},
            ylabel={test label y},
            ]
\addplot+[mark=none]{x^2)};
\end{axis}
\end{tikzpicture}
\end{document}

produces the following image with post-highlited white space with red rectangle:

enter image description here

I have post-highlited the white space with red rectangle that surrounds my image. Left to the y-label and below the x-label. This is what i would like to remove.

Could someone please help me? Thanks for your suggestions!

4
  • use hpekristiansen's answer and uncomment the line starting with label style. That is what you are searching for. Dec 4, 2021 at 17:13
  • What you wrote is not an answer to your question. Dec 4, 2021 at 17:19
  • I think this should be an edit to the question, rather than being posted as an answer. As such it will probably be deleted.
    – Willoughby
    Dec 4, 2021 at 17:29
  • yes, that was a more detailed description of my problem. With the answer from hpekristiansen my problem was solved. At first I was a little confused because of the "border = 1cm" specification that I had overlooked
    – Ben
    Dec 4, 2021 at 17:36

You must log in to answer this question.

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