PGF装饰物未正确居中

PGF装饰物未正确居中

我希望在章节末尾添加漂亮的花饰和装饰,以模仿 19 世纪末书籍的风格。经过一番搜索,图案引起我的注意(一个更用户友好的版本ps 向量) 因为 ps 装饰看起来很棒——正是我想要的。

无论如何,在尝试了几次之后,我发现将 PS 图像居中会产生非常糟糕的结果(见下图)。我应该注意,这些示例比我在真实书籍中使用的要大,但它们被放大了,以便更容易看到图像的中心到底在哪里。不仅图像没有居中,而且图像之间的偏移甚至不一致。这使得这个包完全无法使用......

有经验的人能告诉我这里的问题是否特定于图案(文档声称它仍处于测试阶段)或者问题出在 PS 图像本身的创建方式上(即我是否应该尝试直接使用ps 向量或者会有同样的问题吗?)是否有某种方法可以修复此问题,以便居中环境能够正确地与这些对象配合使用?

居中环境中的 pgf 装饰物不居中!

% !TEX TS-program = xelatex
% !TEX encoding = UTF-8
% this allows us to use real characters like æ instead of macros like \ae

%% PREAMBLE
\documentclass[letterpaper,titlepage,twoside,openany,12pt]{book}

%easier methods for loading fonts and specifying font features
\usepackage{fontspec}
%Use Junicode for access to runes and other nice medieval features
\setmainfont[Language=Icelandic, Fractions=On]{Junicode}
\newcommand{\jfd}{}    %\symbol{"E67D}}

%Switch implementation for end-of-chapter fleurons (below)
\usepackage{xifthen}
\newcommand{\ifequals}[3]{\ifthenelse{\equal{#1}{#2}}{#3}{}}
\newcommand{\case}[2]{#1 #2} % Dummy, so \renewcommand has something to overwrite...
\newenvironment{switch}[1]{\renewcommand{\case}{\ifequals{#1}}}{}

\usepackage[object=vectorian]{pgfornament}
\newcommand{\chapterline}[1]{
    \begin{center}
        \Large\color{myred} 
        \begin{switch}{#1}
            \case{1}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{80}}
            \case{2}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{81}}
            \case{3}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{82}}
            \case{4}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{83}}
            \case{5}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{84}}
            \case{6}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{85}}
            \case{7}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{86}}
            \case{8}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{87}}
            \case{9}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{88}}
            \case{10}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{89}}
        \end{switch}
    \end{center}
}

%Define some colors for the fancy titles
\usepackage{color}
\definecolor{myblue}{rgb}{0,0,0.4}
\definecolor{myred}{rgb}{0.6,0,0}

\usepackage{titlesec}
\titleformat{\chapter}[display]
    {\Huge\filcenter}
    {
        {\Large\color{myred}}\\[0.5cm]
        \color{myblue}\chaptertitlename\ \thechapter\\[0.4cm]
        \color{myred}\jfd
    }
    {0.4cm}
    {\filcenter}
    [\vspace{0.1cm}{\Large\color{myred}}]
\titlespacing*{\chapter}{0pt}{-50pt}{*2.0}

%Customize some margions and other lengths
\usepackage{geometry}
%Although shifted even/odd margins look nice for two sided
%printing, it's distracting when viewing the PDF.
\geometry{outer=1.1in,inner=1.1in}
\geometry{bindingoffset=0cm,hratio=1:1}
%the default bottom margin is huge, make it a bit smaller
\addtolength{\textheight}{0.75in}

\begin{document}
    \mainmatter

    \chapter[Test Ornaments]{Test Ornaments \\ Ornament Test}

    \chapterline{1}

    \chapterline{2}

    \chapterline{3}

    \chapterline{4}

    \chapterline{5}

    \chapterline{6}

    \chapterline{7}

    \chapterline{8}

    \chapterline{9}

    \chapterline{10}

\end{document}

答案1

你的宏中有很多虚假空间。

\newcommand{\chapterline}[1]{%
    \begin{center}
        \Large\color{myred}
        \begin{switch}{#1}%
            \case{1}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{80}}%
            \case{2}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{81}}%
            \case{3}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{82}}%
            \case{4}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{83}}%
            \case{5}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{84}}%
            \case{6}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{85}}%
            \case{7}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{86}}%
            \case{8}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{87}}%
            \case{9}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{88}}%
            \case{10}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{89}}%
        \end{switch}
    \end{center}
}

我得到了完美的居中。

在此处输入图片描述

更好的实现:

\newcommand{\chapterline}[1]{%
  \begin{center}
  \color{myred}
  \pgfornament[anchor=center,ydelta=0pt,width=5cm]{\the\numexpr79+#1}
  \end{center}%
}

答案2

问题在于您对\chapterline(可能继承自您对switch\case(我不太理解)的定义)的定义。

下面我使用一个标准\ifcase来定义命令并得到了想要的结果(我使用 TikZ 在文本区域中间放置一个垂直线作为视觉指南):

% !TEX TS-program = xelatex
% !TEX encoding = UTF-8
% this allows us to use real characters like æ instead of macros like \ae

%% PREAMBLE
\documentclass[letterpaper,titlepage,twoside,openany,12pt]{book}

%easier methods for loading fonts and specifying font features
\usepackage{fontspec}
%Use Junicode for access to runes and other nice medieval features
%\setmainfont[Language=Icelandic, Fractions=On]{Junicode}
\newcommand{\jfd}{}    %\symbol{"E67D}}

\usepackage{tikzpagenodes}

\usepackage[object=vectorian]{pgfornament}
\newcommand{\chapterline}[1]{%
\begin{center}
\LARGE\color{myred}
\ifcase#1\relax
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{80}%
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{81}
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{82}
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{83}
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{84}
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{85}
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{86}
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{87}
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{88}
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{89}
\else
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{90}
\fi
\end{center}
}

%Define some colors for the fancy titles
\usepackage{color}
\definecolor{myblue}{rgb}{0,0,0.4}
\definecolor{myred}{rgb}{0.6,0,0}

\usepackage{titlesec}
\titleformat{\chapter}[display]
    {\Huge\filcenter}
    {
        {\Large\color{myred}}\\[0.5cm]
        \color{myblue}\chaptertitlename\ \thechapter\\[0.4cm]
        \color{myred}\jfd
    }
    {0.4cm}
    {\filcenter}
    [\vspace{0.1cm}{\Large\color{myred}}]
\titlespacing*{\chapter}{0pt}{-50pt}{*2.0}

%Customize some margions and other lengths
\usepackage{geometry}
%Although shifted even/odd margins look nice for two sided
%printing, it's distracting when viewing the PDF.
\geometry{outer=1.1in,inner=1.1in}
\geometry{bindingoffset=0cm,hratio=1:1}
%the default bottom margin is huge, make it a bit smaller
\addtolength{\textheight}{0.75in}

\begin{document}



\chapter[Test Ornaments]{Test Ornaments \\ Ornament Test}

% For testing
\begin{center}
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{80}
\end{center}

    \chapterline{1}

    \chapterline{2}

    \chapterline{3}

    \chapterline{4}

    \chapterline{5}

    \chapterline{6}

    \chapterline{7}

    \chapterline{8}

    \chapterline{9}

    \chapterline{10}

% Just to test the centering
\begin{tikzpicture}[remember picture,overlay]
\draw[line width=2pt,cyan]
  (current page text area.north) -- (current page text area.south); 
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容