为章节标题添加下划线

为章节标题添加下划线

许多文本格式化命令有两种形式:大括号分隔版本和“声明”版本,后者适用于命令后的所有内容。例如\textbfvs \bfseries。但是,有些命令不以这种方式工作。例如,包\ul中的命令soul仅以大括号分隔。

是否可以以非括号分隔的“声明”方式使用它?如果可以,我该怎么做?

具体来说,我正在使用该titlesec包,并希望为章节标题添加下划线。但是,format\titleformat命令的参数似乎只接受“声明”样式的命令。

我怎样才能获得带下划线的章节标题?

答案1

从印刷术上来说,除非你想回到打字机时代,否则不建议这样做。但是,这里有一个解决方案。事实是,的最后一个强制参数\titleformat可能以命令结尾,该命令的参数将是节标题。你可能想要或不想给标签和节标题加下划线,或者只给节标题加下划线:

仅对章节标题添加下划线的解决方案

\documentclass[11pt, a4paper]{article}% http://ctan.org/pkg/amsproc

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{soulutf8} 

\usepackage[]{titlesec}%
\titleformat{\section}
{\Large\bfseries}
{\thesection.}
{0.33em}
{\ul}

\begin{document}

\section {The History of the Seven Families}%

           In former days – that is to say, once upon a time, there lived in the Land of Gramblamble, Seven Families. They lived by the side of the great Lake Pipple-popple (one of the Seven Families, indeed, lived in the Lake), and on the outskirts of the City of Tosh, which, excepting when it was quite dark, they could see plainly. The names of all these places you have probably heard of, and you have only not to look in your Geography books to find out all about them.

\end{document}[![enter image description here][1]][1] 

下划线标签+章节标题的解决方案

此代码为标签和章节标题加下划线:

\titleformat{\section}
{\Large\bfseries}
{\ul{\thesection.\enspace}}
{-0.15em}
{\ul}

在此处输入图片描述

答案2

下划线并大写:

\usepackage{titlesec}
\titleformat{\section}{\fontsize{11}{11}}{}{0cm}{\addulc}
\newcommand{\addulc}[1]{\underline{\MakeUppercase{#1}}}

或者只是强调:

\usepackage{titlesec}
\titleformat{\section}{\fontsize{11}{11}}{}{0cm}{\addul}
\newcommand{\addul}[1]{\underline{#1}}

相关内容