![在文本左侧的空白处设置标题](https://linux22.com/image/338078/%E5%9C%A8%E6%96%87%E6%9C%AC%E5%B7%A6%E4%BE%A7%E7%9A%84%E7%A9%BA%E7%99%BD%E5%A4%84%E8%AE%BE%E7%BD%AE%E6%A0%87%E9%A2%98.png)
我想设置\paragraph
标题的样式,使其位于文本左侧的空白处。我尝试使用该titlesec
包,结果标题被包裹在文本左侧,但不在空白处。
因此,给出以下 MWE:
\documentclass[12pt,]{article}
\usepackage[compact]{titlesec}
\titleformat{\paragraph}[wrap]{\bfseries}{}{}{}[]
\begin{document}
\section{A Section}
Some text. Some text. Some text. Some text. Some text. Some text.
Some text. Some text. Some text. Some text. Some text. Some text.
\paragraph{Heading in the margin}
More text. More text. More text. More text. More text. More text.
More text. More text. More text. More text. More text. More text.
\end{document}
输出看起来像
1 A Section
Some text Some text. Some text. Some text. Some text. Some
text. Some text. Some text. Some text. Some text.
Heading More text. More text. More text. More text. More
in Margin text. More text. More text. More text. More text.
More text. More text.
但我想实现
1 A Section
Some text Some text. Some text. Some text. Some text. Some
text. Some text. Some text. Some text. Some text.
Heading More text. More text. More text. More text. More text. More
in Margin text. More text. More text. More text. More text. More text.
More text.
有什么办法可以解决\titleformat
这个问题吗?或者使用其他机制?
笔记:我知道我可以使用\marginpar
命令直接在页边距打印,但我想保留标题\paragraph
,因为文档部分由 markdown 转换器自动生成。
笔记2:这是我在评论中引用的图片(在这里保留引用,因为我不知道未引用的图像是否会被删除):
注3:pandoc
下面是我在下面的评论中引用的模板片段:
% Redefines (sub)paragraphs to behave more like sections
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
答案1
以下是利用形状可以实现的五个示例leftmargin
:
\documentclass[12pt,]{article}
\usepackage[showframe, marginparwidth=60pt]{geometry}
\usepackage[svgnames, table]{xcolor}
\usepackage{tabularx, makecell, booktabs, eqparbox}
\usepackage[compact, explicit]{titlesec}
\titleformat{\paragraph}[leftmargin]{\bfseries\color{IndianRed}}{}{}{\color{IndianRed}\llap{\parbox[t]{\marginparwidth}{\raggedleft#1}}}[\hskip-\parindent]
\usepackage{lipsum}
\begin{document}
\section{A Section}
Some text. Some text. Some text. Some text. Some text. Some text.
Some text. Some text. Some text. Some text. Some text. Some text.
\paragraph{Heading in the margin}
\lipsum[11]
\titleformat{\paragraph}[leftmargin]{\bfseries\arrayrulecolor{IndianRed}}{}{}%
{\llap{\raisebox{\baselineskip}{\begin{tabularx}{\marginparwidth}[t]{@{}>{\raggedleft\arraybackslash}X@{}}\toprule#1\\\bottomrule\end{tabularx}}}}[\hskip-\parindent]
\paragraph{Another heading}
\lipsum[11]
\titleformat{\paragraph}[leftmargin]{\bfseries}{}{}%
{\llap{\begin{tabularx}{\marginparwidth}[t]{@{}>{\raggedleft\arraybackslash}X!{\color{IndianRed}\vrule width2.5pt}}#1 \end{tabularx}}}[\hskip-\parindent]
\paragraph{Another heading}
\lipsum[11]
\titleformat{\paragraph}[leftmargin]{\bfseries\setlength\fboxrule{1pt}}{}{}%
{\llap{\fcolorbox{IndianRed}{white}{\parbox[t]{\marginparwidth}{\raggedleft#1\\\mdseries(fixed width)}}}}[\hskip-\parindent]
\paragraph{Another heading}
\lipsum[11]
\titleformat{\paragraph}[leftmargin]{\bfseries\setlength\fboxrule{1pt}}{}{}%
{\llap{\raisebox{\dimexpr-\height + \baselineskip-0.5 \fboxrule\relax}{\fcolorbox{IndianRed}{white}{\begin{tabular}[t]{@{}r@{}}\makecell{#1}\end{tabular}}}}}[\hskip-\parindent]
\paragraph{Another\\heading\\\mdseries(variable\\\mdseries width)}
\lipsum[11]
\paragraph{Short\\head}
\lipsum[11]
\end{document}