如何自动计算页面节点内的 tikz 移位

如何自动计算页面节点内的 tikz 移位

我正在尝试正确对齐tikzpicture我放在页脚中的箭头内的文本。我的问题是我希望箭头尖端与页脚的东边缘对齐我希望文本的基线与页脚其他部分的其余文本对齐。

似乎没有一个锚定选项能达到我想要的效果。如果我使用base east锚定,文本会正确对齐,但箭头会突出到边距中,如下所示:

锚点=基点东

我知道如何添加手动换档。在下面的 MWE 中,我有一个或多或少可行的解决方案,即使用yshift将箭头向上拉到正确的位置,但该值是我通过目测确定的。该解决方案如下所示:

在此处输入图片描述

但是,显然它只对这一种尺寸有效。有没有办法tikz自动计算偏移量?

这是我的 MWE:

\documentclass{memoir}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary{positioning,calc,shapes.arrows}
\usepackage{showframe}
\usepackage{lipsum}

\renewcommand*{\ShowFrameColor}{\color{red}}

% This version correctly aligns the CONTINUE text to the baseline,
% but the arrow head sticks out into the margin.
\newcommand{\ContinueNotice}{%
    \begin{tikzpicture}[remember picture,overlay, font={\large\sffamily\bfseries}]
        \node[single arrow,single arrow head extend=3pt,fill=black,text=white,anchor=base east]
        at (current page footer area.south east) {\enspace CONTINUE\enspace};
\end{tikzpicture}%
}

% This version is more or less correctly aligned, but the yshift is done by eye.
\newcommand{\ContinueNoticeAlt}{%
    \begin{tikzpicture}[remember picture,overlay, font={\large\sffamily\bfseries}]
        \node[single arrow,single arrow head extend=3pt,fill=black,text=white,anchor=east,yshift=-2pt]
        at (current page footer area.east) {\enspace CONTINUE\enspace};
\end{tikzpicture}%
}

\makepagestyle{TestStyle}
\makeoddfoot{TestStyle}{\footnotesize Some Notice}{\thepage}{\ContinueNotice}
\makeevenfoot{TestStyle}{\footnotesize Some Notice}{\thepage}{\ContinueNoticeAlt}
\pagestyle{TestStyle}

\begin{document}

\lipsum

\end{document} 

答案1

使用anchor=eastleft作为节点。用 eg 命名节点n,并使用baseline=(n.base)作为 的选项tikzpicture

\documentclass{memoir}
\usepackage{tikzpagenodes}
\usetikzlibrary{shapes.arrows}
\usepackage{showframe}
\usepackage{lipsum}

\renewcommand*{\ShowFrameColor}{\color{red}}

\newcommand{\ContinueNotice}{%
    \begin{tikzpicture}[remember picture,overlay, font={\large\sffamily\bfseries},baseline=(n.base)]
        \node[single arrow,single arrow head extend=3pt,fill=black,text=white,left](n)
        at (current page footer area.south east) {\enspace CONTINUE\enspace};
\end{tikzpicture}%
}

\newcommand{\ContinueNoticeAlt}{%
    \begin{tikzpicture}[remember picture,overlay, font={\large\sffamily\bfseries},baseline=(n.base)]
        \node[single arrow,single arrow head extend=3pt,fill=black,text=white,anchor=east](n)
        at (current page footer area.east) {\enspace CONTINUE\enspace};
\end{tikzpicture}%
}

\makepagestyle{TestStyle}
\makeoddfoot{TestStyle}{\footnotesize Some Notice}{\thepage}{\ContinueNotice}
\makeevenfoot{TestStyle}{\footnotesize Some Notice}{\thepage}{\ContinueNoticeAlt}
\pagestyle{TestStyle}

\begin{document}
\lipsum
\end{document}

在此处输入图片描述


更新

请注意,无需使用tikzpagenodesremember picture。然后您只需运行一次即可。

\documentclass{memoir}
\usepackage{tikz}
\usetikzlibrary{shapes.arrows}
\usepackage{showframe}
\usepackage{lipsum}

\renewcommand*{\ShowFrameColor}{\color{red}}

\newcommand{\ContinueNotice}{%
  \begin{tikzpicture}[overlay, font={\large\sffamily\bfseries},baseline=(n.base)]
    \node[single arrow,single arrow head extend=3pt,fill=black,text=white,left](n)
      {\enspace CONTINUE\enspace};
  \end{tikzpicture}%
}

\newcommand{\ContinueNoticeAlt}{%
  \begin{tikzpicture}[overlay, font={\large\sffamily\bfseries},baseline=(n.base)]
    \node[single arrow,single arrow head extend=3pt,fill=black,text=white,anchor=east](n)
      {\enspace CONTINUE\enspace};
  \end{tikzpicture}%
}

\makepagestyle{TestStyle}
\makeoddfoot{TestStyle}{\footnotesize Some Notice}{\thepage}{\ContinueNotice}
\makeevenfoot{TestStyle}{\footnotesize Some Notice}{\thepage}{\ContinueNoticeAlt}
\pagestyle{TestStyle}

\begin{document}
\lipsum
\end{document}

结果和上面一样。

相关内容