买者自负 ...

买者自负 ...

我对 Latex 还很陌生,在工作中遇到了一些障碍。我正在使用 tikz 和 titlesec 包来生成自定义标题设计。我遇到的问题是找到一种方法让正文从章节标题下方的某个边距开始(高度取决于章节名称的长度),所以我不知道是否有办法以动态方式做到这一点。

谢谢你的时间。

(tkitz章节latex代码原始来源:如何更改章节标题的字体/布局?

示例代码:

\usepackage[explicit]{titlesec}
\usepackage{tikz}
\makeatletter
\newcommand{\gettikzxy}[3]{%
    \tikz@scan@one@point\pgfutil@firstofone#1\relax
    \edef#2{\the\pgf@x}%
    \edef#3{\the\pgf@y}%
}
\makeatother
 \titleformat{\chapter}
    {\normalfont\sffamily\Huge\scshape}
    {}{0pt}
    {\begin{tikzpicture}[remember picture,overlay]
        \node[yshift=-2cm] at (current page.north west)
            {\begin{tikzpicture}[remember picture, overlay]
                \node(chapter)[text width=10cm,anchor=west,xshift=.128\paperwidth,yshift=-.01\paperheight,rectangle]
                            {\color{black}\normalsize CHAPTER \Huge\thechapter};
                \gettikzxy{(chapter)}{\chapterx}{\chaptery}
                \draw[color=black] (0,\chaptery-25) -- ++ (\paperwidth,0);
                \node[text width=13cm,anchor=north west,xshift=.128\paperwidth,yshift=-.065\paperheight,rectangle]
                            {\color{black}\Huge\bfseries\MakeUppercase{#1}};
            \end{tikzpicture}
            };
    \end{tikzpicture}
    }

\titlespacing*{\chapter}{0pt}{50pt}{0pt}

截屏: 在此处输入图片描述

完整代码如下:

\documentclass{report}
\usepackage{kpfonts}
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\usepackage{fancyhdr}
\usepackage{lipsum}% just to generate text for the example
\usepackage{helvet}
\usepackage{palatino}
\usepackage[
  paperwidth=17cm,
  paperheight=24cm,
  bottom = 2cm,
  top = 2cm
  % other options
]{geometry}
\pagestyle{fancy}


\renewcommand{\ttdefault}{ppl}  

\makeatletter
\newcommand{\gettikzxy}[3]{%
    \tikz@scan@one@point\pgfutil@firstofone#1\relax
    \edef#2{\the\pgf@x}%
    \edef#3{\the\pgf@y}%
}
\makeatother

\titleformat{\section}[block]
  {\normalfont\sffamily\fontsize{14}{15}\bfseries}{\thesection }{1em}{#1}




\titleformat{\chapter}
    {\normalfont\sffamily\Huge\scshape}
    {}{0pt}
    {\begin{tikzpicture}[remember picture,overlay]
        \node[yshift=-2cm] at (current page.north west)
            {\begin{tikzpicture}[remember picture, overlay]
                \node(chapter)[text width=10cm,anchor=west,xshift=.128\paperwidth,yshift=-.01\paperheight,rectangle]
                            {\color{black}\normalsize CHAPTER \Huge\thechapter};
                \gettikzxy{(chapter)}{\chapterx}{\chaptery}
                \draw[color=black] (0,\chaptery-25) -- ++ (\paperwidth,0);
                \node[text width=13cm,anchor=north west,xshift=.128\paperwidth,yshift=-.065\paperheight,rectangle]
                            {\color{black}\Huge\bfseries\MakeUppercase{#1}};
            \end{tikzpicture}
            };
    \end{tikzpicture}
    }

\titlespacing*{\chapter}{0pt}{50pt}{0pt}



\makeatletter
\def\footrule{{\if@fancyplain\let\footrulewidth\plainfootrulewidth\fi
    \vskip-\footruleskip\vskip-\footrulewidth
    \leavevmode\rlap{\hspace*{-2in}\rule{2\paperwidth}{\footrulewidth}}
    \vskip\footruleskip}}
\makeatother
\def\headrule{{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
    \vskip-\headruleskip\vskip-\headrulewidth
    \leavevmode\rlap{\hspace*{-2in}\rule{2\paperwidth}{\headrulewidth}}
    \vskip\headruleskip}}
\makeatother


\fancypagestyle{IHA-fancy-style}{%
  \fancyhf{}% Clear header and footer
  \fancyhead[LE,RO]{\sffamily \fontsize{8}{8} \slshape \rightmark}
  \fancyhead[LO,RE]{\fontsize{8}{8} }
  \fancyfoot[RO,LE]{\sffamily \thepage}% Custom footer
  \renewcommand{\headrulewidth}{0.4pt}% Line at the header visible
  \renewcommand{\footrulewidth}{0.4pt}% Line at the footer visible
}

% Redefine the plain page style
\fancypagestyle{plain}{%
  \fancyhf{}%
  \fancyfoot[RO,LE]{\sffamily \thepage}%
  \renewcommand{\headrulewidth}{0.0pt}% Line at the header invisible
  \renewcommand{\footrulewidth}{0.4pt}% Line at the footer visible
}
\pagestyle{IHA-fancy-style}

\begin{document}

        \chapter{Lorem ipsum dolor sit amet, consectetur adipiscing elit vivamus feugiat.}

\lipsum[4]
\section{A Test Section}
\lipsum[1-18]

 \chapter{Introduzione}
\lipsum[4]
\end{document}

答案1

请注意,我无法推荐它,titlesec因为它对我来说从来没用过。不过,我似乎可以用它来回答其他人的问题。

买者自负 ...

这可能给出坏框警告,因此肯定需要整理,但也许这是一个开始。我已经评论了和palatinohelvet你要么想要kpfonts,要么不想要。如果你想要,不要覆盖更改;如果你不想要,不要首先加载这些更改。

这避免了 TiZ,但尽管我心存疑虑,我还是保留了titlesec。它需要calc。我已添加showframegeometry的选项中,以显示页面上元素的位置。显然,您应该在实际文档中删除它。我用它来将“CHAPTER \thechapter”的位置与您的代码放置的位置相匹配。其他间距是目测的,但可以根据需要轻松调整。

\documentclass{report}
\usepackage{kpfonts}
\usepackage[explicit]{titlesec}
\usepackage{fancyhdr,calc}
\usepackage{lipsum}% just to generate text for the example
% \usepackage{helvet} % this an the next line partly overwrite kpfonts - either remove the kpfonts line or remove these; if you remove the kpfonts line, consider using one of the packages which configures all your fonts to include palatino & helvetica clones
% \usepackage{palatino}
\usepackage[
  paperwidth=17cm,
  paperheight=24cm,
  bottom = 2cm,
  top = 2cm,
  showframe,
  % other options
]{geometry}
\pagestyle{fancy}


\renewcommand{\ttdefault}{ppl}  

\makeatletter
\newcommand{\gettikzxy}[3]{%
    \tikz@scan@one@point\pgfutil@firstofone#1\relax
    \edef#2{\the\pgf@x}%
    \edef#3{\the\pgf@y}%
}

\titleformat{\section}[block]{\normalfont\sffamily\fontsize{14}{15}\bfseries}{\thesection }{1em}{#1}

\titleformat{\chapter}
    {\sffamily}
    {}{0pt}
    {%
      \begin{minipage}[t]{\textwidth}
        \normalsize CHAPTER {\Huge\thechapter}\\[-\baselineskip]
        \hspace*{-\Gm@lmargin}\vrule height 0.4pt width \paperwidth\\
        \Huge\bfseries\raggedright\MakeUppercase{#1}
      \end{minipage}%
    }
\makeatother
\titlespacing*{\chapter}{0pt}{-\baselineskip}{20pt}% adjust the last value to change the space between title and text

\makeatletter
\def\footrule{{\if@fancyplain\let\footrulewidth\plainfootrulewidth\fi
    \vskip-\footruleskip\vskip-\footrulewidth
    \leavevmode\rlap{\hspace*{-2in}\rule{2\paperwidth}{\footrulewidth}}
    \vskip\footruleskip}}
\def\headrule{{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
    \vskip-\headsep\vskip-\headrulewidth
    \leavevmode\rlap{\hspace*{-2in}\rule{2\paperwidth}{\headrulewidth}}
    \vskip\headsep}}
\makeatother

\fancypagestyle{IHA-fancy-style}{%
  \fancyhf{}% Clear header and footer
  \fancyhead[LE,RO]{\sffamily \fontsize{8}{8} \slshape \rightmark}%
  \fancyhead[LO,RE]{\fontsize{8}{8} }%
  \fancyfoot[RO,LE]{\sffamily \thepage}% Custom footer
  \renewcommand{\headrulewidth}{0.4pt}% Line at the header visible
  \renewcommand{\footrulewidth}{0.4pt}% Line at the footer visible
}

% Redefine the plain page style
\fancypagestyle{plain}{%
  \fancyhf{}%
  \fancyfoot[RO,LE]{\sffamily \thepage}%
  \renewcommand{\headrulewidth}{0.0pt}% Line at the header invisible
  \renewcommand{\footrulewidth}{0.4pt}% Line at the footer visible
}
\pagestyle{IHA-fancy-style}

\begin{document}

\chapter{Lorem ipsum dolor sit amet, consectetur adipiscing elit vivamus feugiat.}

\lipsum[4]
\section{A Test Section}
\lipsum[1-18]

\chapter{Introduzione}
\lipsum[4]
\end{document}

标题较长的章节

简称章节

相关内容