Change \parskip only inside enumerate & itemize environment - latex

Is there any way that I can change \parskip to a different value inside certain environments, namely enumerate and itemize.
I want to have space between paragraphs (\setlength{\parskip}{1em plus 1pt minus 1pt}), but not inside itemize or enumerate.

If you use the enumitem package, you can say in your preamble
\setlist[itemize]{parsep=0pt}
\setlist[enumerate]{parsep=0pt}
to get what you want. enumitem allows for doing much more list customization, see its documentation for details.

you can also use:
begin{itemize} \itemsep -5pt
\item foo
\item bar
\end{itemize}
and that will only affect the current list.

Yes you can; but you will have to alter either the enumerate and itemize environments from your class file (by copying them and adding your \parskip), or by redefining \#listi, which works for all lists:
\makeatletter
\def\#listi{%
% default settings for base LaTeX classes at 10pt:
\parsep 4pt plus 2pt minus 1pt
\topsep 8pt plus 2pt minus 4pt
\itemsep 4pt plus 2pt minus 1pt
% your settings:
\parskip 1em plus 1pt minus 1pt
}
\makeatother
If you want different settings at nested list levels, change \#listii, \#listiii etc.

The following addition to the preamble updates enumerate to make the suggested change:
\let\oldenumerate\enumerate% Keep a copy of \enumerate (or \begin{enumerate})
\let\endoldenumerate\endenumerate% Keep a copy of \endenumerate (or \end{enumerate})
\renewenvironment{enumerate}
{\begin{oldenumerate}
\setlength{\parskip}{0pt}}% Adjust \parskip to suit your needs
{\end{oldenumerate}}
Here is a complete minimal example showing the adjustment when setting \parskip to 0pt:
\documentclass{article}
\begin{document}
\begin{enumerate}
\item First line
Second line
\end{enumerate}
\let\oldenumerate\enumerate
\let\endoldenumerate\endenumerate
\renewenvironment{enumerate}
{\begin{oldenumerate}
\setlength{\parskip}{0pt}}
{\end{oldenumerate}}
\begin{enumerate}
\item First line
Second line
\end{enumerate}
\end{document}
One would do exactly the same for itemize.

Related

Latex Numbered Hanging \paragraph

I am trying to write a document which uses seperate numbers for sections and paragraphs.
I would like each \paragraph to have a hanging indent such that the first word of the second line, aligns with the first word of the first line.
Here is my code:
\documentclass{article}
\usepackage{a4wide}
\usepackage[english]{babel}
\usepackage{titlesec}
% Heading/Subheading counter
\newcounter{subsubsection}[subsubsection]
\newcounter{param} % Paragraph counter
\newcommand{\N}{%
\noindent\refstepcounter{parnum}%
\makebox[\parindent][l]{\arabic{parnum}.}}
\newcommand\YUGE{\fontsize{60}{100}\selectfont}
% Paragraph style
\renewcommand\thesubsubsubsection{\thesubsubsection.\arabic{subsubsubsection}}
\renewcommand\theparagraph{\thesubsubsubsection.\arabic{paragraph}}
\makeatletter
\renewcommand\paragraph{\#startsection{paragraph}{5}{\z#}%
{1em} {-1em} {\normalsize\normalfont}}
\def\toclevel#subsubsubsection{4}
\def\toclevel#paragraph{5}
\def\l#subsubsubsection{\#dottedtocline{4}{7em}{4em}}
\def\l#paragraph{\#dottedtocline{5}{10em}{5em}}
\makeatother
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\section{Scope}
\pagestyle{style1}
\paragraph*{\N} The Scope of this document should number each paragraph sequentially:
\begin{itemize}
\item [a.] List item 1,
\item [b.] List item 2, and
\item [...] ...
\item [n.] List item n.
\end{itemize}
\paragraph*{\N} Second paragraph with numbering
\subsection{Intro}
\paragraph*{\N} This is the intro.
\paragraph*{\N} Intro cont.
\subsubsection{related docs}
\paragraph*{\N} Here is a list of the related docs
\begin{itemize}
\item [a.] ...
\end{itemize}
\end{document}
This is a picture of what it looks like currently.
Here is a quick example in word as to how I want the paragraphs to work (disregard the different numbering and font type. I am only concerned with the hanging indent).
I found the answer; You need to use the following packages
\usepackage{titlesec}
\usepackage{etoolbox}
Then you need to set the counter depth for the document to 5 and define a new counter. Which means you will be countering every; chapter, section, subsection, subsubsection, paragraph and subparagraph.
\setcounter{secnumdepth}{5}
\newcounter{para}
\newcommand{\N}{\noindent\refstepcounter{para}\makebox[\parindent][l]{\arabic{para}.}}
Now you can set up the format for each of the sections/subsections/paragraphs/etc
\newlength\titleindent
\setlength\titleindent{1.25cm}
\pretocmd{\paragraph}{\stepcounter{subsubsection}}{}{}
\titleformat{\section}{\normalfont\Large\bfseries}{\llap{\parbox{\titleindent}{\thesection\hfill}}}{0em}{}
\titleformat{\subsection}{\normalfont\large\bfseries}{\llap{\parbox{\titleindent}{\thesubsection\hfill}}}{0em}{}
\titleformat{\subsubsection}{\normalfont\normalsize\bfseries}{\llap{\parbox{\titleindent}{\thesubsubsection}}}{0em}{}
\titleformat{\paragraph}[runin]{\normalfont\normalsize}{\llap{\parbox{\titleindent}{\N\hfill}}}{0em}{}
\titlespacing*{\subsubsection}{0pt}{2ex plus 1ex minus 0.2ex}{1.5ex plus .2ex}
\titlespacing*{\paragraph}{0pt}{2ex plus 1ex minus .2ex}{0ex plus 0ex}
I did not use the subparagraph option to I changed the commands such that the numbering of paragraphs is the same level as subsubsections. This means a subsubsection might be numbered 1.2.1 if you have two paragraphs though the next subsubsection will be 1.2.4 is an issue I have yet to solve.
The below is the original commands:
\pretocmd{\paragraph}{\stepcounter{subsection}}{}{}
\pretocmd{\subparagraph}{\stepcounter{subsubsection}}{}{}
Importantly when writing your code, you need to use the following syntax at the beginning of each paragraph:
\paragraph{} Some text
Here is an example
\begin{document}
\section{title}
\subsection{Intro}
\paragraph{} The Scope of this document should number each paragraph sequentially:
\begin{itemize}
\item [a.] List item 1,
\item [b.] List item 2, and
\item [...] ...
\item [n.] List item n.
\end{itemize}
\paragraph{} Second paragraph with numbering, this is sample text to explain the
hanging indent format, which should align with the second line of this paragraph
with the first line.
\subsection{Intro}
\paragraph{}This is the intro, this is sample text to explain the hanging indent
format, which should align with the second line of this paragraph with the first
line.
\paragraph{} Intro cont, this is sample text to explain the hanging indent format,
which should align with the second line of this paragraph with the first line.
\subsubsection{related docs}
\paragraph{} Here is a list of the related docs
\begin{itemize}
\item [a.] ...
\end{itemize}
\end{document}
This is what it looks like now

How to align an enumerated list in latex?

Suppose I want to center align the enumerated list. I did this:
\begin{center}
\begin{enumerate}[label=(\Roman*)]
\item Equation 1
\item Equation 2
\item Equation 3
\item Equation 4
\end{enumerate}
\end{center}
This is not working nicely. I have also tried without 'enumerate' and just 'center' and labeling manually. It does work but the alignment is not looking perfect.
Also instead for center we can also do:
I. Equation 1 \quad II. Equation 2
III. Equation 3 \quad IV.Equation 4
You cannot center an item list like that. Enumerate is a formatting environment that will supersedes the center environment.
What can be done is to put the enumerate list in a box (like a minipage), and to center this box.
Standard minipage requires a width, but there is a package (varwidth) that allows to define minipages with an unknown width (more precisely, you give a width parameter, but if width is smaller than that, the actual with is used).
So here is a solution with varwidth.
\documentclass{article}
\usepackage{enumitem}
\usepackage{varwidth}
\usepackage{tasks}
\begin{document}
\begin{center}
\begin{varwidth}{\textwidth}
\begin{enumerate}[label=(\Roman*)]
\item Equation 1
\item Equation 2
\item Equation 3
\item Equation 4
\end{enumerate}
\end{varwidth}
\end{center}
\end{document}
If you want to have several enumerate items per line, your solution is not very robust, as you must adjust the spacing depending on the item length if you want your items to be aligned.
The 'tabto' package provides a way to do the alignment in a flexible way. But the best solution is to use the 'tasks' package that allows to define columned list. This package is not as smart as others to determine the item width and, if required, this must be given explicitely. The parenthesized parameter is the number of columns. As previously, if you want to center globally the environment, you must use varwidth.
\begin{center}
\begin{varwidth}{\textwidth}
\begin{tasks}[label={(\Roman*)},label-width={1cm}](2)
\task Equation 1
\task Equation 2
\task Equation 3
\task Equation 4
\end{tasks}
\end{varwidth}
\end{center}
For simple lists like yours, a tabular could also be used.
You can just use
\begin{enumerate}[label=(\Roman*)]\centering

Aligning numbered paragraphs

I am trying to cross reference some numbered paragraphs. I am using \numpar but the first one always is off aligned. (\item didn't work)
Here is what I did:
\section{First section}
\subsection*{Subsection1}
\numpar\label{A1} blablabla1
\numpar\label{A2} blablabla2
\numpar\label{A3} blablabla3
\section{Second section}
Statement \ref{A2} = 2 must be true.
which results in:
I need all numbers to be aligned without affecting on unnumbered paragraphs. I am open to other commands instead of \numpar if any. Any advice is appreciated.
Why don't you use enumerate? It is done for that kind of problem.
\documentclass{article}
\begin{document}
\section{First section}
\subsection*{Subsection1}
\begin{enumerate}
\item \label{A1} blablabla1
\item \label{A2} blablabla2
\item \label{A3} blablabla3
\end{enumerate}
\section{Second section}
Statement \ref{A2} = 2 must be true.
\end{document}
If required, you can customize the appearance with the enumitem package.
For instance, to increase the indentation, load the package, and start enumerate with :
\begin{enumerate}[leftmargin=3cm]`
Many options in the enumitem package and it can certainly fit your needs.
Edit:
Note that \item will indent anything that is after it. If you dont want this behavior, close the enumerate before your paragraph. Then you can restart the enumerate, but you must take care of the item numbering (see below).
\documentclass{article}
\usepackage{enumitem}
\begin{document}
\section{First section}
\subsection*{Subsection1}
\begin{enumerate}
\item \label{A1} blablabla1
This paragraph will be indented
\end{enumerate}
But this one will not.
\begin{enumerate}\setcounter{enumi}{1}
% This insures that item numbering will be coherent
% set it to the value of the last item
% If using the enumitem package, there is a simpler way with 'resume'
% \begin{enumerate}[resume]
\item \label{A2} blablabla2
\item \label{A3} blablabla3
\end{enumerate}
And another non indented par
\section{Second section}
Statement \ref{A2} = 2 must be true.
\end{document}

columns with itemize

I'm trying to make alignment points in a list environment. The following code gives me an error, but it almost compiles to what I want, just missing the bullet points. I must be misunderstanding something about align and/or tabular and how they work with linebreaks. Guidance appreciated!
\documentclass{beamer}
\begin{document}
\begin{frame}
\frametitle{Title}
\begin{itemize}
\begin{tabular}{ll}
\item Topic Apple: &Something to say about it \\
\item Topic Watermelons: &Something different
\end{tabular}
\end{itemize}
\end{frame}
\end{document}
How about this?
\documentclass{beamer}
\begin{document}
\begin{frame}
\frametitle{Title}
\begin{tabular}{p{0.4\textwidth}p{0.5\textwidth}}
\begin{itemize}
\item Topic Apple:
\item Topic Watermelon:
\end{itemize} &
\begin{itemize}
\item[] Something to say about it
\item[] Something to say about it
\end{itemize} \\
\end{tabular}
\end{frame}
\end{document}
Yours will actually work if you change {ll} to {p{width}l} or {p{width}p{width}} but I found that if you don't have itemize in the second column, your text ends up vertically top aligned while the itemized text in the left column is center (or maybe even slightly bottom) aligned vertically so it doesn't look good.
I tried using the array package and m{width} which provides a vertical center alignment but that was still different than whatever itemize is using. I'd say just play with the width argument inside of p{} to get the spacing/width you want. If your right column spills on to another line, you may need a "dummy" item in the right column.
Anyway, based on all the jimmy rigging that might be necessary if things spill onto two lines, I'm assuming my solution is potentially hackish but it looks like it provides what you want for the most part.
the \item[] for the right column is to create the same itemize alignment with no bullet. If you want bullets on the right, just remove the empty square brackets and you'll have them.

Eliminate space before \begin{itemize} [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 4 years ago.
Improve this question
In Latex, how do I eliminate the space inserted before itemize?
\begin{itemize} % produces lots of vertical space
\item ...
\item ...
\end{itemize}
The way to fix this sort of problem is to redefine the relevant list environment. The enumitem package is my favourite way to do this sort of thing; it has many options and parameters that can be varied, either for all lists or for each list individually.
Here's how to do (something like) what it is I think you want:
\usepackage{enumitem}
\setlist{nolistsep}
or
\usepackage{enumitem}
\setlist{nosep}
Try \vspace{-5mm} before the itemize.
Use \vspace{-\topsep} before \begin{itemize}
Use \setlength{\parskip}{0pt} \setlength{\itemsep}{0pt plus 1pt} after \begin{itemize}
And for the space after the list, use \vspace{-\topsep} after \end{itemize}
\vspace{-\topsep}
\begin{itemize}
\setlength{\parskip}{0pt}
\setlength{\itemsep}{0pt plus 1pt}
\item ...
\item ...
\end{itemize}
\vspace{-\topsep}
The cleanest way for you to accomplish this is to use the enumitem package (https://ctan.org/pkg/enumitem). For example,
\documentclass{article}
\usepackage{enumitem}% http://ctan.org/pkg/enumitem
\begin{document}
\noindent Here is some text and I want to make sure
there is no spacing the different items.
\begin{itemize}[noitemsep]
\item Item 1
\item Item 2
\item Item 3
\end{itemize}
\noindent Here is some text and I want to make sure
there is no spacing between this line and the item
list below it.
\begin{itemize}[noitemsep,topsep=0pt]
\item Item 1
\item Item 2
\item Item 3
\end{itemize}
\end{document}
Furthermore, if you want to use this setting globally across lists, you can use
\usepackage{enumitem}% http://ctan.org/pkg/enumitem
\setlist[itemize]{noitemsep, topsep=0pt}
However, note that this package does not work well with the beamer package which is used to make presentations in Latex.
The "proper" LaTeX ways to do it is to use a package which allows you to specify the spacing you want. There are several such package, and these two pages link to lists of them...
TeX FAQ entry How to adjust list spacing
http://dcwww.camd.dtu.dk/~schiotz/comp/LatexTips/LatexTips.html
I'm very happy with the paralist package. Besides adding the option to eliminate the space it also adds other nice things like compact versions of the itemize, enumerate and describe environments.
\renewcommand{\#listI}{%
\leftmargin=25pt
\rightmargin=0pt
\labelsep=5pt
\labelwidth=20pt
\itemindent=0pt
\listparindent=0pt
\topsep=0pt plus 2pt minus 4pt
\partopsep=0pt plus 1pt minus 1pt
\parsep=0pt plus 1pt
\itemsep=\parsep}

Resources