我使用 tikz 制作了一张标签。我对此非常满意,但有些事情让我感到困扰。标签的第一行与其他行相比稍微靠右一点,我不知道为什么。
以下是代码:
\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}
答案1
注意命令定义中的空格。如果你删除它们或用%
注释标记隐藏它们,它就会起作用:
\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}}