Outils pour utilisateurs

Outils du site


pele_mele:stack_exchange:tex-391569

Why the first tikz element is a bit off?

I've made a sheet of label using tikz. I am pretty happy about it but there is something that bothers me. The first row of label is a little bit of to the right compared to other rows and I don't know why.

Here is the code:

\documentclass{article}
 
\usepackage[a4paper]{geometry}
\geometry{bottom=2cm}
\usepackage{tikz}
\usepackage{fontspec}
 
\setmainfont{Sketch Nothing}
 
\usetikzlibrary{calc,decorations.pathmorphing,patterns}
 
\newcommand\myLabel[1]{
    \begin{tikzpicture}[decorate]
        % Outside of the label
        \node[text width=7cm, text height=3cm](myLabel) {};
        \draw[line width=1pt,line cap=rect,lightgray] (myLabel.north west) -| (myLabel.south east) -| (myLabel.north west) -- cycle;
 
        % Text
        \node[font=\fontsize{34}{25}\selectfont,align=center,darkgray]{#1};
        \node[anchor=east,font=\fontsize{12}{16}\selectfont,align=center,darkgray] at ([xshift=-0.25cm,yshift=-2.75cm]myLabel.north east) {\year};
    \end{tikzpicture}
}
 
\newcommand\myLabelRow[1]{
    \myLabel{#1} \myLabel{#1}
}
 
\begin{document}
    \pagenumbering{gobble}
    \def \year{2017}
 
    \noindent
    \myLabelRow{Sureau}
    \myLabelRow{Sureau}
    \myLabelRow{Sureau}
    \myLabel{Sureau} \myLabel{Cerise}
    \myLabelRow{Abricot}
    \myLabelRow{Abricot}
    \myLabelRow{Mure}
    \myLabelRow{Mure}
    \myLabelRow{Tomate\\ verte}
    \myLabelRow{Tomate\\ verte}
    \myLabelRow{Rhubarbe\\ Fraise}
    \myLabelRow{Rhubarbe\\ Fraise}
    \myLabel{Rhubarbe\\ Fraise} \myLabel{Prunelle}
    \myLabelRow{Prunelle}
 
\end{document}

Pay attention to the empty spaces inside your command definitions. If you remove them or suppress them with % comment markers, it works:

\newcommand\myLabel[1]{%
    \begin{tikzpicture}[decorate]
        % Outside of the label
        \node[text width=7cm, text height=3cm](myLabel) {};
        \draw[line width=1pt,line cap=rect,lightgray] (myLabel.north west) -| (myLabel.south east) -| (myLabel.north west) -- cycle;
 
        % Text
        \node[font=\fontsize{34}{25}\selectfont,align=center,darkgray]{#1};
        \node[anchor=east,font=\fontsize{12}{16}\selectfont,align=center,darkgray] at ([xshift=-0.25cm,yshift=-2.75cm]myLabel.north east) {\year};
    \end{tikzpicture}%
}
 
\newcommand\myLabelRow[1]{\myLabel{#1} \myLabel{#1}}
pele_mele/stack_exchange/tex-391569.txt · Dernière modification : 2020/11/18 11:02 de alexis