5

How can I improve, in a way ideally not requiring manual (automatic may be OK!) tinkering with (half) linewidths and scaling factors, the look of this axis intersection:

Here's what I have (left), and what I want (right):

enter image description here enter image description here

And here's my MWE:

\documentclass[tikz,border=3pt]{standalone}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis x line = middle,
        axis y line = middle,
        xtick = \empty,
        ytick = \empty,
        xmin = 0,
        xmax = 1,
        ymin = 0,
        ymax = 1,
        width = 2cm,
        height = 2cm,
    ]\end{axis}
\end{tikzpicture}
\end{document}
bers
  • 5,404

1 Answers1

9

x axis line style={shorten <=-0.5\pgflinewidth} is one option, and while you do say you don't want to tinker with half line widths, at least that one gets the width of the path, so if you add e.g. thick to the axis options, it still works.

Another option is x axis line style={line cap=rect}, see section 15.3.1 Graphic Parameters: Line Width, Line Cap, and Line Join in the manual for TikZ.

output of code

\documentclass[tikz,border=3pt]{standalone}
\usepackage{pgfplots} % loads tikz
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis x line = middle,
        axis y line = middle,
        x axis line style={line cap=rect},
%        x axis line style={shorten <=-0.5\pgflinewidth},
        xtick = \empty,
        ytick = \empty,
        xmin = 0,
        xmax = 1,
        ymin = 0,
        ymax = 1,
        width = 2cm,
        height = 2cm,
    ]\end{axis}
\end{tikzpicture}
\end{document}
Torbjørn T.
  • 206,688
  • Well, automatic tinkering is sort of OK, but the line cap is of course the perfect solution :) – bers Dec 23 '17 at 11:27
  • line cap=rect sounds like a good solution for this problem. Do you have experience with this setting? Does it have limitations? Otherwise it might be a good candidate for the default in pgfplots. – Christian Feuersänger Dec 23 '17 at 12:48
  • @ChristianFeuersänger I don't know much about it really. I've only ever played with line cap a couple of times, so I can't say more than what the manual says. – Torbjørn T. Dec 23 '17 at 12:53
  • @ChristianFeuersänger, this question pops up from time to time (e.g. https://tex.stackexchange.com/q/327217/95441). I also would recommend to use line cap=rect as default for the axis lines. There should be no limitation/side effect, if you just add it to the axis line style. – Stefan Pinnow Dec 23 '17 at 18:14