如何为每个段落设置横向边距,但不为其他元素设置横向边距?

如何为每个段落设置横向边距,但不为其他元素设置横向边距?

我希望在宽页面内获得窄段落,以便章节标题、图形、表格都可能很宽,而段落都可能很窄。

\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}

相关内容