2

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}
8

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}}
  • 4
    You're stealing my favorite job of adding %! ;-) – egreg Sep 15 '17 at 20:58
  • 2
    @egreg - you can have your job back if you promise to translate your LaTeX book into English. Deal? – Michael Palmer Sep 15 '17 at 21:12
  • 3
    You'll have to continue chasing for missing %, I'm afraid. ;-) – egreg Sep 15 '17 at 21:29

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.