13

How do I change all line width proportionally to one another for example by a factor of two?

Here is an MWE to illustrate the problem:

\documentclass[tikz, border = 1cm]{standalone}

%some magic line which changes all the line width by a factor of two

\begin{document}

\begin{tikzpicture}

    \draw[thin]  (0,0) -- ++(2,0);

    \draw        (0,1) -- ++(2,0);

    \draw[thick] (0,2) -- ++(2,0);

\end{tikzpicture}

\end{document}

This is not related to pgfplots - How can I set all the default line widths / thickness values to a certain value? because I dont just want to change one line widths.

The default line width should not be change.

  • The MWE is very useful because we now know that you want to use thin, thick and alike, but wish for a one-line way of changing all of these definitions. So yes, the MWE is needed. – Tiuri Aug 31 '17 at 10:18
14

The line widths thin, thick, etc. are defined liked this (taken from here):

\tikzset{
    ultra thin/.style= {line width=0.1pt},
    very thin/.style=  {line width=0.2pt},
    thin/.style=       {line width=0.4pt},
    semithick/.style=  {line width=0.6pt},
    thick/.style=      {line width=0.8pt},
    very thick/.style= {line width=1.2pt},
    ultra thick/.style={line width=1.6pt}
}

So I would suggest to replace this definition with every line widths given as a multiple of some length variable (say \mylinewidth). You can then change the value of \mylinewidth globally or locally, and the lines with these options will adjust their widths.

Example (note the comment below):

\documentclass{article}
\usepackage{tikz}

\newlength\mylinewidth
\setlength\mylinewidth{0.4pt}

\tikzset{
    ultra thin/.style= {line width=0.25\mylinewidth},
    very thin/.style=  {line width=0.5\mylinewidth},
    thin/.style=       {line width=\mylinewidth},
    semithick/.style=  {line width=1.5\mylinewidth},
    thick/.style=      {line width=2\mylinewidth},
    very thick/.style= {line width=3\mylinewidth},
    ultra thick/.style={line width=4\mylinewidth},
    every picture/.style={semithick}
}

\begin{document}

\begin{tikzpicture}
    \draw[very thin]  (0,0) -- ++(2,0);
    \draw        (0,1) -- ++(2,0);
    \draw[very thick] (0,2) -- ++(2,0);
\end{tikzpicture}
\hspace{1cm}
\setlength\mylinewidth{1pt}
\begin{tikzpicture}
    \draw[very thin]  (0,0) -- ++(2,0);
    \draw        (0,1) -- ++(2,0);
    \draw[very thick] (0,2) -- ++(2,0);
\end{tikzpicture}

\end{document}

enter image description here

Note: In this example, I used semithick as the default line width because it appeared visually right to me. You can of course use the standard default which is every picture/.style={thin}.

  • 1
    Very nice answer. – Steven B. Segletes Aug 31 '17 at 10:34
  • Good answer. Sad this isnt a function in pgf. Why do you use every picture/.style={semithick}? – JulianWgs Aug 31 '17 at 10:51
  • 1
    @Julian_W: Try to leave that out, and \draw without an option will not join in the scaling. So with this line I make semithick the default for all pictures, and all lines (even without an own specified width) will be affected by a change of \mylinewidth. – Tiuri Aug 31 '17 at 10:55
  • why dont you use the standard \thin? – JulianWgs Aug 31 '17 at 10:56
  • @Julian_W I had the visual impression that semithick was the standard. In case I assumed wrongly, feel free to make a different choice in your code. – Tiuri Aug 31 '17 at 11:04

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.