Outils pour utilisateurs

Outils du site


pele_mele:stack_exchange:tex_latex:391569

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
pele_mele:stack_exchange:tex_latex:391569 [2024/11/23 04:02] – supprimée - modification externe (Date inconnue) 127.0.0.1pele_mele:stack_exchange:tex_latex:391569 [2024/11/23 04:02] (Version actuelle) – ↷ Nom de la page changé de pele_mele:stack_exchange:tex_latex:tex-391569 à pele_mele:stack_exchange:tex_latex:391569 alexis
Ligne 1: Ligne 1:
 +====== 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:
 +
 +<code latex>
 +\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}
 +</code>
 +
 +<WRAP help>
 +
 +
 +Pay attention to the empty spaces inside your command definitions. If you remove them or suppress them with % comment markers, it works:
 +
 +<code latex>
 +\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}}
 +</code>
 +</WRAP>
 +<WRAP info>
 +[[https://tex.stackexchange.com/questions/391569/why-the-first-tikz-element-is-a-bit-off|Why the first tikz element is a bit off? - TeX - LaTeX Stack Exchange]]
 +</WRAP>