Page LayoutOne half Spacing in the Paragraph

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
upani1982
Posts: 43
Joined: Wed May 12, 2010 11:42 am

One half Spacing in the Paragraph

Post by upani1982 »

Dear All,

I am facing problem regarding spacing in my paragraphs. I want one half spacing across all the paragraphs in my documents. But when i am trying the space before and after section is also changing. I am not able to track the problem.

Code: Select all

\newlength{\aftersection}
\setlength{\aftersection}{0pt}
\addtolength{\aftersection}{-1\parskip}
\newlength{\beforesection}
\setlength{\beforesection}{0pt}
\addtolength{\beforesection}{-1\parskip}
\setlength\abovedisplayskip{0pt}
\setlength\belowdisplayskip{0pt}
After \begin{document} I have put in

Code: Select all

\onehalfspacing
\parindent=0.3in
\parskip=1pt
I have got this code from this forum but unable to understand the meaning of each command. Although i have mentioned one half spacing after the beginning of the document but unable to do so. I want your valuable suggestion as i am a beginner without much latex knowledge.

Your small help can help me a lot.

With sincere regards,
Upananda

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

One half Spacing in the Paragraph

Post by frabjous »

We need a complete minimal working example showing what document class you are using, what packages you are loading, and so on.
upani1982
Posts: 43
Joined: Wed May 12, 2010 11:42 am

One half Spacing in the Paragraph

Post by upani1982 »

Hi,

I am extremely sorry for not providing the information as specified by you. The code follows here.

Code: Select all

\documentclass[12pt,a4paper]{article}
\usepackage[british]{babel}
\usepackage{microtype,times,pslatex}
\usepackage[sort&compress]{natbib}
\usepackage[small,compact]{titlesec}
\newlength{\aftersection}
\setlength{\aftersection}{0pt}
\addtolength{\aftersection}{-1\parskip}
\newlength{\beforesection}
\setlength{\beforesection}{0pt}
\addtolength{\beforesection}{-1\parskip}
%\titlespacing*{\section}{0pt}{\beforesection}{\aftersection}
%\titlespacing*{\subsection}{0pt}{\beforesection}{\aftersection}
%\titlespacing*{\subsubsection}{0pt}{\beforesection}{\aftersection}
\setlength\abovedisplayskip{0pt}
\setlength\belowdisplayskip{0pt}
\setlength{\bibsep}{0pt}
\usepackage[fleqn]{amsmath}
\usepackage[T1]{fontenc}
\usepackage[top=1.5cm,bottom=1.5cm,left=2.5cm,right=1.5cm]{geometry}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage{pdflscape}
\bibpunct{(}{)}{;}{a}{,}{;}
\begin{document}
\setcounter{page}{1}
\pagenumbering{arabic}
\parindent=0.3in
\parskip=1pt
\restoregeometry
\onehalfspacing
\end{document}
You can correct me if i have not given the correct information.

With sincere regards,
Upananda
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

One half Spacing in the Paragraph

Post by frabjous »

OK, so the next question is -- what behavior do you want to see with the section titles? It wasn't clear. Keep in mind that, as usually formatted, the titles are themselves typeset as paragraphs, and hence are affected by spacing commands. Also, the space before and after will be affected by spacing applied to the paragraphs before and after them. But again, I'm not sure what look you're after.

Since you're having trouble tracking what's doing what, let's walk through your code and discuss what each part of it is doing. I'm going to suggest making some changes unrelated to your problems, just to clean things up a bit.

Code: Select all

\documentclass[12pt,a4paper]{article}
\usepackage[british]{babel}
Begins the article with 12pt fonts on A4 paper with British-style hyphenation rules. No problem here.

Code: Select all

\usepackage{microtype,times,pslatex}
The microtype package adds some microtypography rules. It's fine.

The times and pslatex packages are generally considered obsolete (see l2tabu), though you can still use them. If you want Times fonts, I'd suggest using either mathptmx or txfonts packages. However, it would be best to load these after amsmath and after the fontenc package.

Code: Select all

\usepackage[sort&compress]{natbib}
As you probably know, this is for greater citation control.

Code: Select all

\usepackage[small,compact]{titlesec}
This is the package which is affecting the spacing of the titles -- if you don't want to make changes to how the titles are handled, I'd leave this package out altogether. If you do want to make changes to how titles are handled, this is the package to use.

Code: Select all

\newlength{\aftersection}
\setlength{\aftersection}{0pt}
\addtolength{\aftersection}{-1\parskip}
\newlength{\beforesection}
\setlength{\beforesection}{0pt}
\addtolength{\beforesection}{-1\parskip}
%\titlespacing*{\section}{0pt}{\beforesection}{\aftersection}
%\titlespacing*{\subsection}{0pt}{\beforesection}{\aftersection}
%\titlespacing*{\subsubsection}{0pt}{\beforesection}{\aftersection}
Here you define some new lengths, set them to one thing, and them immediately change them to something else. This is all a bit silly. Even sillier given that you've commented out the titlespacing* commands (from titlesec) that use these commands. Hence, as is, these commands do nothing at all. I'd just cut all this out. I'll make some suggestions about using titlesec below if you still want to.

Code: Select all

\setlength\abovedisplayskip{0pt}
\setlength\belowdisplayskip{0pt}
These commands remove the spacing before and after displayed math in your document. However, the \onehalfspacing command also sets these lengths. Since \onehalfspacing comes after these, these commands are overridden and hence have no effect. I think how \onehalfspacing works here is fine, but if you wanted these to do anything at all, you'd have to put them after \onehalfspacing. Personally, I'd just cut them out.

Code: Select all

\setlength{\bibsep}{0pt}
This removes extra space between items in the bibliography. It's fine if you want it that way.

Code: Select all

\usepackage[fleqn]{amsmath}
\usepackage[T1]{fontenc}
\usepackage[top=1.5cm,bottom=1.5cm,left=2.5cm,right=1.5cm]{geometry}
\usepackage{graphicx}
These are pretty standard things, but I'd the first three earlier in the preamble, since they affect the document in kind of a global way, and amsmath tends to cause problems if it's not loaded early.

Code: Select all

\usepackage{setspace}
This package is what provides the \onehalfspacing for changing the spacing for the document.

Code: Select all

\usepackage{pdflscape}
This is for rotating certain pages of the output when put into landscape. I assume you know why you need this here.

Code: Select all

\bibpunct{(}{)}{;}{a}{,}{;}
A natbib command for formatting internal citations. I assume you have this the way you want it.

Code: Select all

\begin{document}
Self-explanatory.

Code: Select all

\setcounter{page}{1}
\pagenumbering{arabic}
These do nothing in this context. The \pagenumbering command always resets the page number, so the first command would do nothing anyway, but since arabic is the default anyway, this is not necessary. But perhaps in your document there is something else before this.

Code: Select all

\parindent=0.3in
\parskip=1pt
The parindent value sets how far the first line of a paragraph is indented horizontally to the right. 0.3 inches seems like quite a lot to me -- personally I'd stick with the default, but if you like it that way, then fine. The parskip value is extra space added in between one paragraph and another, so here you're adding 1 point of space extra between paragraphs. Did you mean to do that? It does not seem compatible with what you said you wanted, so I'd cut at least the second line out.

Code: Select all

\restoregeometry
A command from the geometry package to undo the effects of a previous \newgeometry command. Since you haven't used any of those, this does nothing.

Code: Select all

\onehalfspacing
This is the command from the setspace package which makes for one and a half-spacing.

Code: Select all

\end{document}
So, if I were to clean that up, and do it my own way, I'd start with a document like this:

Code: Select all

\documentclass[12pt,a4paper]{article}
\usepackage[top=1.5cm,bottom=1.5cm,left=2.5cm,right=1.5cm]{geometry}
\usepackage{microtype}
\usepackage[UKenglish]{babel}
\usepackage[fleqn]{amsmath}
\usepackage[T1]{fontenc}
\usepackage{txfonts}
%
% put titlesec stuff here if you want
%
\usepackage[sort&compress]{natbib}
\setlength{\bibsep}{0pt}
\bibpunct{(}{)}{;}{a}{,}{;}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage{pdflscape}
\begin{document}
\onehalfspacing
% rest of document
\end{document}
If I wanted to fiddle with the formatting and spacing of the titles, I'd load titlesec. (To me, the natural place to put this would be after loading txfonts but before loading natbib, but probably anywhere in the preamble would be fine.)

For maximal control, I'd skip options like compact and small and do my format with \titleformat and \titlespacing. Perhaps with the comments I put in, you can get a sense how these work. But do read the titlesec documentation too.

Code: Select all

\usepackage{titlesec}
\titleformat{\section}% applies to section level
    [hang]% shape of section title; see p.3 of titlesec doc
    {\bfseries\large}% commands applied to whole title
    {\thesection.}% the number
    {0.5em}% space between number and title
    {}% commands applied just to title, not number
   
\titlespacing*{\section}%
    {0pt}% Space to left of section title
    {0pt}% extra space before section title
    {0pt}% extra space after section title 
%
\titleformat{\subsection}% applies to subsection level
    [hang]% shape of section title; see p.3 of titlesec doc
    {\bfseries}% commands applied to whole title
    {\thesubsection.}% the number
    {0.5em}% space between number and title
    {}% commands applied just to title, not number
   
\titlespacing*{\subsection}%
    {0pt}% Space to left of subsection title
    {0pt}% extra space before subsection title
    {0pt}% extra space after subsection title 
Note, that the spaces can be negative, so if you wanted to undo the effects of \onehalfspacing, you could put in e.g., a negative number for the extra space before a title.
upani1982
Posts: 43
Joined: Wed May 12, 2010 11:42 am

Re: one half spacing in the paragraph

Post by upani1982 »

Hi Frabjous,

I am grateful to you for your timely help and it has helped me to learn latex in an easy way.

With sincere regards,
Upananda
Post Reply