2

I'm having this problem with tikz in which I'm trying to create this simple number line but a load of unnecessary white spaces pops up:

 \item
As a real-number-line graph:\\
    \begin{tikzpicture}
        \begin{axis}[
            axis x line=middle,
            axis y line=none,
            xtick={-3,-2,...,4,5}
        ]
            \addplot[line width=0.4mm, draw=blue][domain=-3:5]{0};
            \addplot[draw=blue, fill=white, mark=*] coordinates {(-3,0)(1,0)(5,0)};
        \end{axis}
    \end{tikzpicture}
\item
Interval Notation:\\

The result looks like this:

enter image description here

How would I remove all this white space? Also, why is there so much white space?

Thanks.

6
  • 1
    Welcome! You need to set the ‘height ‘ and ‘width’ of the axis to the values you like.
    – user194703
    Sep 12, 2019 at 5:48
  • 2
    Hi, welcomme , Please give a compileable minimum example starting with \documentclass{...} and ending with \end{document}
    – AndréC
    Sep 12, 2019 at 5:49
  • @Schrödinger'scat Thank you so much; exactly what I needed.
    – ssp
    Sep 12, 2019 at 5:54
  • You're welcome! (Most likely you have a \pgfplotset{...,width=...} and/or \pgfplotset{...,width=...} somewhere in your file. If you remove this global option you should also be fine.
    – user194703
    Sep 12, 2019 at 7:17
  • @Schrödinger'scat I don't, actually. I do have \usepackage[margin=1in]{geometry} but I doubt that affects anything..
    – ssp
    Sep 12, 2019 at 7:38

1 Answer 1

3

tikzpicture in has default height. You need to reduce it to some small value, but not to small (<16mm) since than you will receive error:

Package pgfplots Error: Error: Plot height `42.67912pt' is too small. This ca
nnot be implemented while maintaining constant size for labels. Sorry, label si
zes are only approximate. You will need to adjust your height..

See, if the following MWE gives what you like to have:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{enumerate}
\item   As a real-number-line graph:

\begin{tikzpicture}
    \begin{axis}[
height=20mm, width=90mm,    % <---
axis x line=bottom,
axis y line=none,
axis line style=-,          % <---
xtick={-3,-2,...,4,5},
ymin = 0, ymax = 1,         % <---
                ]
\addplot[draw=blue, thick, fill=white, mark=*]  
    coordinates {(-3,0) (1,0) (5,0)};
    \end{axis}
\end{tikzpicture}
\item   Interval Notation:
\end{enumerate}
\end{document}

enter image description here

0

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.