如何為每個段落設定橫向邊距,而不是其他元素?

如何為每個段落設定橫向邊距,而不是其他元素?

我想在寬頁面中獲得窄段落,以便章節標題、圖形、表格都可以是寬的,而段落都可以是窄的。

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\setlength{\parindent}{0pt} % so we can see better what is happening

\newenvironment{narrowpar}% I’d like every paragraph to follow these rules.
{\begin{list}{}{%
\setlength{\listparindent}{\parindent}%
\setlength{\itemindent}{\parindent}%
\setlength{\leftmargin}{2cm}%
\setlength{\rightmargin}{2cm}%
}\item }%
{\end{list}}

\begin{document}    

\section{A section title that ranges across the page}

This is a paragraph (Loret Ipsum So On). And below, an equation that can make use of the whole page width:

\begin{equation}
p v = R T
\end{equation}

Here is another paragraph.

\begin{narrowpar}
This very text looks exactly the way I would like my paragraphs to look. But unfortunately it forces me to insert code manually before and after every paragraph in the source file.
\end{narrowpar}

\end{document}

我希望獲得什麼

換句話說,我試圖控制所有段落的橫向空間(HTML/CSS 中的「左右填滿」),而不使用頁邊距。我將不勝感激任何幫助...

答案1

您可以嘗試使用\parshape命令重新定義段落形狀:

\parshape 1 .15\hsize.65\hsize

參數 1:第一行,參數對:.15\hsize.65\hsize左邊距和右邊距。所有其他行將與第一行一樣縮排。

它僅適用於存在該命令的段落。因此,您必須\parshape重新定義\par,即:

\def\par{\ifhmode\ownpar\fi\endgraf}
\def\ownpar{\parshape 1 .15\hsize.65\hsize}

相關內容