![将部分与文本主体对齐](https://linux22.com/image/366936/%E5%B0%86%E9%83%A8%E5%88%86%E4%B8%8E%E6%96%87%E6%9C%AC%E4%B8%BB%E4%BD%93%E5%AF%B9%E9%BD%90.png)
我正在尝试将节的标题与下面的正文对齐,以便节号相对于正文具有负边距。请参见此处:
以下 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}