它应该是什么样子
我想使用 实现以下结果TikZ
。图形应与文本主体的右侧对齐,并与所在行的文本顶部对齐。
此外,图形应该“覆盖”以下线条。
我到目前为止尝试过什么以及它看起来如何
图形本身应该放在命令中,比这个 MWE 中的图形更复杂。我尝试了很多方法,包括、、baseline
等等,但都无法让它工作……无论是对齐,还是“覆盖”。overlay
xshift
yshift
\documentclass[parskip=half]{scrartcl}
\usepackage{tikz}
\usepackage{xparse}
\NewDocumentCommand \goodluck { } {
\hfill
\tikz[baseline=1.75cm, overlay]{%
% Do some more complex TikZ stuff
\fill[blue] (0, 0) rectangle (1, 1);
\fill[red] (0, 1) rectangle (1, 2);
}
}
\setlength{\parindent}{0pt}
\begin{document}
Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli
Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla \goodluck
Blub Blub Blub Blub Blub Blub Blub Blub Blub Blub Blub Blub Blub Blub
\end{document}
答案1
使用 KOMA 选项时,段落最后一行parskip=half
必须至少有自由空间。因此,使用 \hfill 时,文本主体的右边框的距离为。1em
1em
\documentclass[parskip=half]{scrartcl}
\usepackage{tikz}
\usepackage{xparse}
\NewDocumentCommand \goodluck { } {
\hfill
\tikz[baseline=(n.base)]{%
\node[inner sep=0pt,outer sep=0pt,anchor=north east](n)at(-1em,0){\strut};
\begin{pgfinterruptboundingbox}% -> overlays its contents
% Do some more complex TikZ stuff
\fill[red] (0,0) rectangle (-1,-1);
\fill[blue] (0,-1) rectangle (-1,-2);
\draw(-4,0)--(4,0)(0,-4)--(0,4);% to show the alignment and the origin of the picture
\end{pgfinterruptboundingbox}
}
}
\begin{document}
Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli Bli
Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla \goodluck
Blub Blub Blub Blub Blub Blub Blub Blub Blub Blub Blub Blub Blub Blub
\end{document}