Latex:列表前后的垂直空间

发布于 2024-10-03 01:26:49 字数 218 浏览 2 评论 0原文

我无法摆脱列表前后的垂直空间。我有如下代码:

\begin{list}{-}{}
    \setlength{\itemsep}{0pt}
    \setlength{\parskip}{0pt}
    \setlength{\parsep}{0pt}

    \item First item
    \item Second item

\end{list}

I cannot get rid of the vertical space before and behind the lists. I have code like below:

\begin{list}{-}{}
    \setlength{\itemsep}{0pt}
    \setlength{\parskip}{0pt}
    \setlength{\parsep}{0pt}

    \item First item
    \item Second item

\end{list}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情话难免假 2024-10-10 01:26:49

更新的答案:现在同时考虑单行和多行列表项。


一个订单项(简单)
逐项列出而不逐项...

Some text that is here and I want to see what it does. \\
  \indent$\bullet$\,first item \\
  \indent$\bullet$\,second item \\
Some text that is here and I want to see what it does.

$\bullet$ 替换为您想要的任何内容。

\indent- first item\\
\indent$\cdot$\,first item\\
\indent$\circ$\,first item\\
\indent$\ast$\,first item\\

如图所示,“-”似乎与空格配合得很好,但其余的需要尾随 \, 在数学符号和下一个单词之间插入一个空格。如果没有它,“项目符号”和后面的文本之间就没有空格。


多行项目(稍微复杂一点)
嗯,没那么复杂。刚刚找到了关于执行“悬挂缩进”的参考,这似乎使其足够灵活,可以做任何您想做的事情。 [1]

\documentclass{article}

\begin{document}

\newlength{\originalParindent} %see comments below
\setlength{\originalParindent}{\parindent} 

Some text that is here and I want to see what it does and to show the current
indentation behavior of a blob of text. Some text that is here and I want to
see what it does. Some text that is here and I want to see what it does. \par

\leftskip .3in % see comments below
\parindent -0.09in % see comments below

\indent$\bullet$\,first item that spills onto a second line to demonstrate the
function of leftskip and it's ability to make hanging indents. Might as well
make sure we hit three lines with this first item to be sure it works.\\

\indent$\bullet$\,second item can run onto a second line as well; hopefully
this solves the problem\par

\leftskip 0in %reset the defaults
\setlength{\parindent}{\originalParindent} %resent the defaults

Some text that is here and I want to see what it does. Just want to make sure
the defaults are restored and paragraphs indent with their proper functionality.

\end{document}

评论

  • Parindent stuff:我们将欺骗事情看起来像一个逐项项目符号,其中多行缩进以匹配第一个缩进的文本。为此,我们需要调整 parindentleftskip 值。 Leftskip 通常为零,但我不知道 parindent 设置为什么,因此我们将其保存在变量中并稍后恢复。在试图找到相当于 \setlength{\parindent}{default} 的东西时发现了这个技巧。[2]

  • leftskip:这与整体缩进的距离有关。如果您希望它更靠右,只需增加该值即可。零意味着项目符号与段落向左齐平。

  • parindent:这会覆盖使后续行与项目符号左边缘对齐的默认行为。 -0.9 值恰好看起来适合补偿项目符号和空格,以便后续行看起来与第一行匹配。你也可以调整这个。例如,这样的东西可能看起来更好。

项目符号和文本之间的间距更大;家长相应调整:

\leftskip .3in % see comments below
\parindent -0.215in % see comments below

\indent$\bullet$\quad first item that spills onto a second line to demonstrate
the function of leftskip and it's ability to make hanging indents. Might as
well make sure we hit three lines with this first item to be sure it works.\\

希望有帮助! parindent 和 leftskip 手柄应该可以让您完善您想要的东西。


[1] http://www.wkiri.com/today/?p=76

[2] http://www .cs.cmu.edu/afs/cs/usr/bovik/database/tsf-bboard/Tex/enumerate

Updated answer: now accounts for both single and multi-line list items.


One line items (simple)
Itemize without itemizing...

Some text that is here and I want to see what it does. \\
  \indent$\bullet$\,first item \\
  \indent$\bullet$\,second item \\
Some text that is here and I want to see what it does.

Replace $\bullet$ with whatever you want.

\indent- first item\\
\indent$\cdot$\,first item\\
\indent$\circ$\,first item\\
\indent$\ast$\,first item\\

The "-" seems to work fine with the whitespace as shown but the rest need the trailin \, which inserts a space between the math symbol and the next word. Without it there will be no space between the "bullet" and the text that follows.


Multi-line items (just a tad more complex)
Well, not much complex. Just found a reference about doing "hanging indents" which appears to make this flexible enough to do whatever you want. [1]

\documentclass{article}

\begin{document}

\newlength{\originalParindent} %see comments below
\setlength{\originalParindent}{\parindent} 

Some text that is here and I want to see what it does and to show the current
indentation behavior of a blob of text. Some text that is here and I want to
see what it does. Some text that is here and I want to see what it does. \par

\leftskip .3in % see comments below
\parindent -0.09in % see comments below

\indent$\bullet$\,first item that spills onto a second line to demonstrate the
function of leftskip and it's ability to make hanging indents. Might as well
make sure we hit three lines with this first item to be sure it works.\\

\indent$\bullet$\,second item can run onto a second line as well; hopefully
this solves the problem\par

\leftskip 0in %reset the defaults
\setlength{\parindent}{\originalParindent} %resent the defaults

Some text that is here and I want to see what it does. Just want to make sure
the defaults are restored and paragraphs indent with their proper functionality.

\end{document}

Comments

  • Parindent stuff: we're going to trick things into looking like an itemized bullet with multiple lines indented to match the first indented text. To do this we fiddle with parindent and leftskip values. Leftskip is usually zero but I don't know what parindent is set to so we save it in a variable and restore it later. Found this trick while trying to find something equivalent to \setlength{\parindent}{default}.[2]

  • leftskip: this plays with how far the overall thing is indented. If you want it further to the right, just increase the value. Zero means the bullets are flush left with the paragraphs.

  • parindent: this overrides the default behavior of making the subsequent lines aligned with the left edge of our bullet. The -0.9 value just happens to look right for compensating for the bullet and the space so that subsequent lines look like they're matched up with the first line. You can tweak this, too. For example, something like this might look better.

Bigger space between bullet and text; parindent adjusted accordingly:

\leftskip .3in % see comments below
\parindent -0.215in % see comments below

\indent$\bullet$\quad first item that spills onto a second line to demonstrate
the function of leftskip and it's ability to make hanging indents. Might as
well make sure we hit three lines with this first item to be sure it works.\\

Hope that helps! The parindent and leftskip handles should allow you to perfect what you want.


[1] http://www.wkiri.com/today/?p=76

[2] http://www.cs.cmu.edu/afs/cs/usr/bovik/database/tsf-bboard/Tex/enumerate

青衫负雪 2024-10-10 01:26:49

这是 Hendy 答案的延续: Latex:之前的垂直空间在列表后面

我记下了他的笔记,并准备了以下内容:

\newlength{\originalParindent}                                            
\newenvironment{my_itemize}
{
    \setlength{\originalParindent}{\parindent}                            
    \leftskip .3in                                                        
    \parindent -0.11in

    \newcommand{\originalItem}{\item}                                     
    \renewcommand{\item}{\indent - }                                      
}
{                                                                         
    \par

    \leftskip 0in
    \setlength{\parindent}{\originalParindent}                            
    \renewcommand{\item}{\originalParindent}                              
}   

之后我只能写:

\begin{my_itemize}

     \item Something very short

     \item Somethnig very long. Somethnig very long. Somethnig very long. Somethnig very long. Somethnig very long. Somethnig very long.

\end{my_itemize}

在我的文档中的任何位置获取正确的列表。

It is continuation of Hendy answer: Latex: Vertical space before and behind the lists

I took his notes and I prepared the following:

\newlength{\originalParindent}                                            
\newenvironment{my_itemize}
{
    \setlength{\originalParindent}{\parindent}                            
    \leftskip .3in                                                        
    \parindent -0.11in

    \newcommand{\originalItem}{\item}                                     
    \renewcommand{\item}{\indent - }                                      
}
{                                                                         
    \par

    \leftskip 0in
    \setlength{\parindent}{\originalParindent}                            
    \renewcommand{\item}{\originalParindent}                              
}   

After that I can only write:

\begin{my_itemize}

     \item Something very short

     \item Somethnig very long. Somethnig very long. Somethnig very long. Somethnig very long. Somethnig very long. Somethnig very long.

\end{my_itemize}

To get proper list wherever in my document.

面犯桃花 2024-10-10 01:26:49

扩展之前的答案,一个根本没有要点的变体,而是第一行没有缩进,其他行(从第二行开始)有缩进:

\newenvironment{table_itemize}
{
    \begingroup                 % Start of formatting properties

    \leftskip 0.1in             % indentation for lines except first line
    \parindent -0.1in           % first line: no indentation

    \renewcommand{\item}{}      % no bullets
}{
    % restore all formatting that we changed since begingroup
    % (e.g. leftskip, parindent)
    \endgroup
}

然后,按照 Kogut 帖子中已经指出的相同方式使用:

\begin{table_itemize}

    \item Something very short

    \item Something very long. Something very long. Something very long. Something very long. Something very long. Something very long.

\end{table_itemize}

Expanding on the previous answers, a variation with no bullet points at all, but instead first lines without indentation, and other lines (from 2nd line onwards) with indentation:

\newenvironment{table_itemize}
{
    \begingroup                 % Start of formatting properties

    \leftskip 0.1in             % indentation for lines except first line
    \parindent -0.1in           % first line: no indentation

    \renewcommand{\item}{}      % no bullets
}{
    % restore all formatting that we changed since begingroup
    % (e.g. leftskip, parindent)
    \endgroup
}

Then, use in the same way as already indicated in post by Kogut:

\begin{table_itemize}

    \item Something very short

    \item Something very long. Something very long. Something very long. Something very long. Something very long. Something very long.

\end{table_itemize}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文