![如何為每個段落設定橫向邊距,而不是其他元素?](https://rvso.com/image/254717/%E5%A6%82%E4%BD%95%E7%82%BA%E6%AF%8F%E5%80%8B%E6%AE%B5%E8%90%BD%E8%A8%AD%E5%AE%9A%E6%A9%AB%E5%90%91%E9%82%8A%E8%B7%9D%EF%BC%8C%E8%80%8C%E4%B8%8D%E6%98%AF%E5%85%B6%E4%BB%96%E5%85%83%E7%B4%A0%EF%BC%9F.png)
我想在寬頁面中獲得窄段落,以便章節標題、圖形、表格都可以是寬的,而段落都可以是窄的。
\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}