我正在尝试将节的标题与下面的正文对齐,以便节号相对于正文具有负边距。请参见此处:
以下 MWE 尝试创建上述输出:
\documentclass[a4paper,12pt]{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{titlesec}
\titleformat{\section}%
{\LARGE\bfseries}% format applied to label+text
{\hspace{-40pt} \LARGE\bfseries\thesection}% label
{20pt}% horizontal separation between label and title body
{}% before the title body
[]% after the title body
\begin{document}
\section{asd}
\blindtext
\end{document}
当然,\hspace{-40pt}
我希望避免使用手册。有没有办法确定的宽度\thesection
?
答案1
一个简单的方法是使用零宽度的右对齐框:
\documentclass[a4paper,12pt]{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{titlesec}
\titleformat{\section}%
{\LARGE\bfseries}% format applied to label+text
{\makebox[0cm][r]{\thesection\hspace{20pt}}}% label
{0pt}% horizontal separation between label and title body
{}% before the title body
[]% after the title body
\begin{document}
\section{asd}
\blindtext
\addtocounter{section}{1000}
\section{asd}
\blindtext
\end{document}