使用 Tikz 自定义部分标题

使用 Tikz 自定义部分标题

我正在尝试使用 tikz 获得这种结果。但是我不知道如何将文本与矩形底部对齐,或者如何将第二个矩形与标题行锚定最后结果

在此示例中,第一个标题是章节标题,第二个标题是小节标题。

%!TEX program = xelatex
    \documentclass{memoir}
    \usepackage\[paperwidth=10.5cm,paperheight=15.5cm, margin=0.9cm\]{geometry}
    \usepackage{xcolor}
    \usepackage\[explicit\]{titlesec}
    \usepackage{lipsum}
    \definecolor{sec}{HTML}{DD5C14}
    \definecolor{band}{HTML}{EE9C52}

    \usepackage{fontspec}
    \newfontfamily{\helveticacdb}{Helvetica-CondensedBlack}
    % \newfontfamily{\helveticacdl}{Helvetica-CondensedLight}

    \usepackage\[T1\]{fontenc}

    \titleformat{\section}\[hang\]{\helveticacdb\fontsize{1.2cm}{0.95cm}\bfseries}{}{0.5ex}%
      {\begin{minipage}{0.975\textwidth}%
      \noindent
      \color{band}%
      \llap{\vrule width0.7cm height 0.7cm depth0ex\hskip0.25ex}%
      \textcolor{sec}{\unskip#1}%
      \hskip0.25ex%
      \rlap{\vrule width\textwidth height 0.7cm    depth0ex}%
    \end{minipage}}\[\smallskip\]

    \titleformat{\subsection}\[hang\]{\helveticacdb\fontsize{0.45cm}{0.5cm}\bfseries}{}{0.5ex}%
      {\noindent%
      \color{band}%
      \raisebox{0.222ex}{\hbox to \textwidth{%
      \vrule width1.3ex height1ex depth0ex\hskip0.5ex%
      \raisebox{-0.222ex}{\textcolor{sec}{#1}}%
      \hskip0.75ex%
      \leaders\vrule height 0.2cm depth0ex\hfil}}}\[\smallskip\]

    \titleformat{\subsubsection}\[hang\]{\helveticacdb\fontsize{0.3cm}{0.3cm}\bfseries}{}{0.5ex}{
      \textcolor{sec}{\unskip#1}%
    }%

    % Remove the header while starting a new section
    \let\footruleskip\undefined
    \usepackage{fancyhdr}
    % \renewcommand{\sectionmark}\[1\]{\markright{#1}{}}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
    \fancyhf{}
    \renewcommand{\sectionmark}\[1\]{\markboth{\chaptername \ \thesection. #1}{}}
    % \lhead{\leftmark}

    % Start sections on a new page
    \usepackage{etoolbox}
    \patchcmd{\section}{plain}{empty}{}{}
    \pretocmd{\section}{%
      \ifnum\value{section}=0 \else\clearpage\fi
    }{}{}
    % manage multicolumns after each section title
    \usepackage{multicol}

    \AtBeginDocument{\begin{multicols}{2}}
    \AtEndDocument{\end{multicols}}

    \makeatletter
    \let\subsection@orig\subsection
    \renewcommand\subsection\[1\]{\endmulticols\subsection@orig{#1}\multicols{2}}
    \makeatother

    \begin{document}
    \section\[Politique et économie\]{Politique\\ et économie}
      \subsection{POLITIQUE}
        \subsubsection{First subsub}
          \lipsum\[1-2\]

    \end{document}

结果

剩余问题:

  • 每次出现新的部分时清除页码。
  • 粘住左边的橙子正方形至页面左边框。

答案1

没有 TikZ。但还远远不够完美。

\documentclass{memoir}
\usepackage[paperwidth=10.5cm,paperheight=15.5cm,headheight=0.5in]{geometry}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}

\definecolor{sec}{HTML}{DD5C14}
\definecolor{band}{HTML}{EE9C52}

\titleformat{\section}[hang]{\sffamily\Huge\bfseries}{}{0.5ex}%
  {\begin{minipage}{0.975\textwidth}%
  \noindent
  \color{band}%
  \llap{\vrule width\textwidth height1ex depth0ex\hskip0.75ex}%
  \textcolor{sec}{\unskip#1}%
  \hskip0.75ex%
  \rlap{\vrule width\textwidth height1ex depth0ex}%
\end{minipage}}[\smallskip]

\titleformat{\subsection}[hang]{\sffamily\Large\bfseries}{}{0.5ex}%
  {\noindent%
  \color{band}%
  \raisebox{0.222ex}{\hbox to 0.975\textwidth{%
  \vrule width2ex height1ex depth0ex\hskip0.5ex%
  \raisebox{-0.222ex}{\textcolor{sec}{#1}}%
  \hskip0.75ex%
  \leaders\vrule height1ex depth0ex\hfil}}}[\smallskip]

\begin{document}
\section[Politique et \'economie]{Politique \\ et \'economie}

Blablabla \ldots le politique et l'\'economie

\subsection{POLITIQUE}

Quelle horreur!

\end{document}

在此处输入图片描述

相关内容