我正在尝试根据一些品牌指南创建文档,这些指南要求使用有角度和彩色的部分标题。
xcolor
我使用和包使颜色工作正常sectsty
,但找不到如何旋转标题。
我也尝试过使用该rotating
包。它对普通文本很有效,但当我尝试将其用于某个部分时,它会抛出错误。
这是我的工作示例:
\documentclass{article}
\usepackage{helvet}
\usepackage{xcolor}
\definecolor{my-green}{RGB}{134,162,11}
% Section Styling
\usepackage{sectsty}
\sectionfont{\huge \color{my-green}}
\begin{document}
\section{I'd like to rotate this}
\end{document}
编辑
根据以下答案,下面是我最终用来解决问题的代码:
\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage[explicit]{titlesec}
\usepackage{graphicx}
\usepackage{xcolor}
\definecolor{scout-green}{RGB}{134,162,11}
\definecolor{scout-purple}{RGB}{77,33,119}
\newif\ifwithrotation
\newcommand \basictitlebeforecode[1] {
\parbox[t]{\dimexpr\textwidth\relax}{\raggedright#1}
}
\newcommand \fulltitlebeforecode[1] {
\ifwithrotation
\rotatebox{6}{\basictitlebeforecode{#1}}
\else
\basictitlebeforecode{#1}
\fi
}
\usepackage[explicit]{titlesec}
\titleformat{\section}[hang]
{\Huge\sffamily\bfseries\color{scout-green}}
{}{0em}
{\fulltitlebeforecode{#1}}
\titleformat{\subsection}[hang]
{\LARGE\sffamily\bfseries\color{scout-purple}}
{}{0em}
{\fulltitlebeforecode{#1}}
\begin{document}
\section{Ordinary Short Section}
\subsection{Ordinary Short Subsection}
\withrotationtrue
\section{Rotated Short Section}
\subsection{Rotated Short Subsection}
\withrotationfalse
\section{This is a purposely long section title that extends on more than one line}
\subsection{This is a purposely long subsection title that extends on more than one line}
\withrotationtrue
\section{This is a purposely long rotated section title that extends on more than one line}
\subsection{This is a purposely long rotated subsection title that extends on more than one line}
\withrotationfalse
\end{document}
答案1
titlesec
以下是使用和可以完成的操作的示例graphicx
。请参阅 titlesec 的文档,尤其是有关间距的内容。
\documentclass{book}
\usepackage[a4paper, showframe]{geometry}
\usepackage[explicit]{titlesec}
\usepackage{graphicx}
\usepackage{xcolor}
\definecolor{my-green}{RGB}{134,162,11}
\usepackage{mathtools}
\titleformat{\section}[hang]{\huge\sffamily\bfseries\color{my-green}}{}{0em}{\rotatebox{9}{\arabic{section}.\enspace\parbox[t]%
{\dimexpr\linewidth-2em\relax}{\raggedright#1}}}
\pagestyle{plain}
\begin{document}
\section{This is a short title}
This is a paragraph.
\section{This is a purposely long title that extends on more than one line}
This is a paragraph.
\end{document}
答案2
LaTeX 用于标题的底层\@startsection
机制旨在允许字体规范中的最后一条命令成为带参数的命令,以允许旋转、大写等。此功能由包承担secsty
。
\documentclass{article}
\usepackage{helvet}
\usepackage{xcolor,graphicx}
\definecolor{my-green}{RGB}{134,162,11}
% Section Styling
\usepackage{sectsty}
\sectionfont{\huge \color{my-green}\rotatebox{10}}
\begin{document}
\tableofcontents
\section{I'd like to rotate this}
\section{I'd like to rotate this as well}
\end{document}