问题图片

问题图片

我遇到了一个奇怪的问题。出于某种原因,我编译得越多,节点内的文本位就会被推得越来越靠右。如果我激活overlay自定义命令的选项,垂直间距就会变成假的,这又带来了另一个麻烦。

我怎样才能使节点内的文本左对齐(黑框式摇动)?

问题图片

在此处输入图片描述

平均能量损失

% !TeX spellcheck = en_Us

\documentclass[
a4paper,
DIV=15,
german,
%landscape,
%footheight=10pt,
fontsize=10pt,
]{scrartcl}

\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary{
backgrounds,
positioning,
calc,
matrix
}

\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\newlength{\xdistance}
\setlength{\xdistance}{4pt}
\newlength{\yAbstand}
\setlength{\yAbstand}{10pt}

\newcommand{\specialsec}[1]{%
    %\raisebox{-0.2\height}{%
    \begin{tikzpicture}[
    remember picture=true,
%   overlay,
    ]
    \node[
%   xshift=-5pt,
    %draw=\specialsechintergrund,
    inner xsep=0pt,
    outer xsep=0pt,
    inner ysep=2pt,
    outer ysep=2pt,
    font=\LARGE\rmfamily,
    text=black,
    %text=white,
    align=left,
    anchor=south west,
    %   yshift=-1.0cm,
    %   minimum height=1.85cm,
    %xshift=2em,
    ]
    (AbschnittNode) {%
        #1%
    };%
    %### Nodes/Koordinaten für Abschnittsüberschrift setzen
    \draw[
    inner xsep=0pt,
    outer xsep=0pt,
    inner ysep=0pt,
    outer ysep=0pt,
    ]
    ($(AbschnittNode.west -| current page text area.west)+(\xdistance,\yAbstand)$) coordinate (AbschnittBoxRO)
    ($(AbschnittNode.west -| current page text area.west)+(\xdistance,-\yAbstand)$) coordinate (AbschnittBoxRU)
    ($(AbschnittNode.west -| current page text area.west)+(0pt,-\yAbstand)$) coordinate (AbschnittBoxLU)
    ($(AbschnittNode.west -| current page text area.west)+(0pt,\yAbstand)$) coordinate (AbschnittBoxLO)
    ;
    \begin{pgfonlayer}{foreground}
    \fill[
        inner sep=0pt,
        outer sep=0pt,
        fill=black,
    ]
    ($(AbschnittBoxLO -| current page text area.west)+(-\xdistance,0pt)$) rectangle ($(AbschnittBoxLU)+(0,-0.8pt)$);
    \end{pgfonlayer}
    \draw[
    ultra thick,
    black,
    ] ($(AbschnittBoxLU -| current page text area.west)+(0,0)$) -- ($(AbschnittBoxRU -| current page text area.east)+(0pt,0)$);
    \end{tikzpicture}%
}

\listfiles

\begin{document}
Here are some words to form some random text.
1: The quick brown fox jumps over the lazy dog.
2: The quick brown fox jumps over the lazy dog.
3: And more words. Not really making sense.
4: Again the thing with the quick brown fox.

\begin{flushleft}
\specialsec{Something words}
\end{flushleft}

Here are some words to form some random text.
1: The quick brown fox jumps over the lazy dog.
2: The quick brown fox jumps over the lazy dog.
3: And more words. Not really making sense.
4: Again the thing with the quick brown fox.


\begin{flushleft}
\specialsec{Another thing}
\end{flushleft}

Here are some words to form some random text.
1: The quick brown fox jumps over the lazy dog.
2: The quick brown fox jumps over the lazy dog.
3: And more words. Not really making sense.
4: Again the thing with the quick brown fox.

\end{document}

答案1

overlay只有在实际引用时才需要current page text area,因此将其添加到您的\fills 和\draws 中,您会得到:

在此处输入图片描述

但是,您实际上并不需要remember picturecurrent page text area节点。

您确切地知道文本区域的左侧在哪里。 那就是您放置 TikZ 图片的地方。 只需将您想要的内容放在图片的左侧即可。

而且你也知道右侧在哪里,它\textwidth比左侧更靠右。

代码

% !TeX spellcheck = en_Us

\documentclass[a4paper, DIV=15, german, fontsize=10pt]{scrartcl}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{tikz}

\newlength{\xdistance}
\setlength{\xdistance}{4pt}
\newlength{\yAbstand}
\setlength{\yAbstand}{10pt}
\tikzset{
  specialsec node/.style={
    inner sep=+0pt, inner ysep=+2pt, font=\LARGE\rmfamily,
    text=black, align=left, anchor=base},
  specialsec left/.style=black,
  specialsec line/.style=ultra thick}
\newcommand{\specialsec}[2][]{%
  \par\bigskip\noindent
  \begin{tikzpicture}[baseline, trim left=(sol), trim right=(eol),#1]
    \node[specialsec node] (AbschnittNode) {#2};
    \fill[specialsec left]([shift=(AbschnittNode.west)]0pt,\yAbstand)
      rectangle +(-\xdistance,-2\yAbstand) coordinate (sol);
    \draw[specialsec line] ([xshift=+\xdistance,yshift=+.5\pgflinewidth]sol)
      -- +(right:\textwidth) coordinate (eol);
  \end{tikzpicture}%
  \par\bigskip}

\listfiles

\begin{document}
Here are some words to form some random text.
1: The quick brown fox jumps over the lazy dog.
2: The quick brown fox jumps over the lazy dog.
3: And more words. Not really making sense.
4: Again the thing with the quick brown fox.

\specialsec{Something words}

Here are some words to form some random text.
1: The quick brown fox jumps over the lazy dog.
2: The quick brown fox jumps over the lazy dog.
3: And more words. Not really making sense.
4: Again the thing with the quick brown fox.

\specialsec[specialsec line/.append style=green]{Another thing}

Here are some words to form some random text.
1: The quick brown fox jumps over the lazy dog.
2: The quick brown fox jumps over the lazy dog.
3: And more words. Not really making sense.
4: Again the thing with the quick brown fox.

\end{document}

输出

在此处输入图片描述

答案2

tcolorbox您也可以在这种环境中使用。我认为这比您的建议更简单。

% !TeX spellcheck = en_Us
\documentclass[
a4paper,
DIV=15,
german,
%landscape,
%footheight=10pt,
fontsize=10pt,
]{scrartcl}

\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[most]{tcolorbox}

\newtcolorbox{myspecialsec}[1][]{%
sharp corners,
fontupper=\LARGE\rmfamily,
leftrule=4pt,
bottomrule=2pt,
toprule=0pt,
rightrule=0pt,
halign=left,
boxsep=1pt,
left=0pt,
bottom=0pt,
top=0pt,
colback=white,
#1
}

\listfiles

\begin{document}
Here are some words to form some random text.
1: The quick brown fox jumps over the lazy dog.
2: The quick brown fox jumps over the lazy dog.
3: And more words. Not really making sense.
4: Again the thing with the quick brown fox.

\begin{myspecialsec}
Something words
\end{myspecialsec}

Here are some words to form some random text.
1: The quick brown fox jumps over the lazy dog.
2: The quick brown fox jumps over the lazy dog.
3: And more words. Not really making sense.
4: Again the thing with the quick brown fox.

\begin{myspecialsec}[colframe=red!70!black]
Another thing
\end{myspecialsec}

Here are some words to form some random text.
1: The quick brown fox jumps over the lazy dog.
2: The quick brown fox jumps over the lazy dog.
3: And more words. Not really making sense.
4: Again the thing with the quick brown fox.

\end{document}

在此处输入图片描述

相关内容