Text FormattingUpdate: Add a line above/below section title (titlesec pkg)

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
jjmm
Posts: 13
Joined: Tue Jul 12, 2016 5:23 am

Update: Add a line above/below section title (titlesec pkg)

Post by jjmm »

Hi

The question on my previous post seems to be solved. My present question is how to adjust the space between the line "above" the title and the end of the paragraph. Now the space is too wide, and I would like to narrow it. Could someone tell me how to do it? Thanks!

codes:

Code: Select all

\documentclass[11pt]{article}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{graphicx}
\usepackage[margin=1in]{geometry}
\usepackage{fancyhdr}
\usepackage[shortlabels]{enumitem}
\usepackage{enumitem}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\definecolor{Blue}{rgb}{0,0,0.8}
\setlength{\parindent}{0pt}
\setlength{\parskip}{5pt plus 1pt}
\setlength{\headheight}{1pt}
\numberwithin{equation}{section} 

\titleformat{\section}
{\normalfont\large\bfseries\color{Blue}}
{\titlerule\vspace{1pt}}
{1em}
{\vspace{0.1in}\hrule\hspace{-12pt}\thesection\hspace{1pt}{.}\hspace{1pt} #1}
[{\titlerule[0.4pt]}]


\newcommand\question[2]{\vspace{.25in}\hrule\textbf{#1. #2}\vspace{.5em}\hrule\vspace{.10in}}
\renewcommand\part[1]{\vspace{.10in}\textbf{(#1)}}
\pagestyle{fancyplain}
\lhead{\textbf{\NAME}}
\chead{\textbf{Econ 100A HW\HWNUM}}
\rhead{\today}
\begin{document}\raggedright

\newcommand\NAME{John Smith}  
\newcommand\HWNUM{3}              
\section{First section}
kkk
\section{Lucas puzzle}
yyy
\section{PPP}
\section{Capital Control and NDF}
xxxx
\section{Cagan variant and exchange rates}
\begin{enumerate}[(a)]
	\item\item  Cagan model
	\begin{eqnarray}
m_t-p_t=-\eta i_{t+1}+\phi y_t,	
	\end{eqnarray}
	where money demand 
\end{enumerate}


\end{document}
Last edited by cgnieder on Wed Sep 14, 2016 8:30 pm, edited 1 time in total.

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Update: Add a line above/below section title (titlesec pkg)

Post by cgnieder »

Hi

I'm not sure I correctly understood your question:
My present question is how to adjust the space between the line "above" the title and the end of the paragraph.
You mean the spacing between a paragraph and a following section title?

You can use \titlespacing for adjusting such spaces. In the example below I also provide an alternative definition for your title format:

Code: Select all

\documentclass{article}

\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\definecolor{Blue}{rgb}{0,0,0.8}

\titleformat{\section}
  {\normalfont\large\bfseries\color{Blue}}% format
  {}% label
  {0pt}% sep
  {\titlerule\newline\llap{\thetitle. }#1}% before code
  [{\titlerule[0.4pt]}]% after code

\titlespacing{\section}
  {0pt}% left
  {0pt}% before sep
  {\baselineskip}% after sep

\usepackage{lipsum}

\begin{document}

\lipsum[1]

\section{Section Title}
\lipsum[1]

\end{document}
titlesec.png
titlesec.png (74.45 KiB) Viewed 17885 times
Regards
site moderator & package author
Post Reply