# lines above and below section

I'm currently using the code below for making section-like titles in a two-column document

    \newcommand{\titulo}[1]
{
\par\medskip
\begin{noindent}
\rule{\linewidth}{0.8pt}
\fontsize{14pt}{0pt}{\selectfont\textbf{#1\\}}
\rule{\linewidth}{0.8pt}
\end{noindent}
}


and

\begin{document}

Some results
\titulo{Discusión y Análisis}
Some analysis

\end{document}


getting someting like:

But I want that the space after the above line to be equal to the one below, and there's a little space at the beggining of the rule.

Also, how do I make this to be the default \section format?

• Definitely don't use \title with \newcommand as you will get errors with any standard (and the vast majority of non-standard) classes. titlesec is a popular package for customising section titles. Personally, I'm not keen but everyone else seems to find it works fine. (I find it works fine when I use it to solve other people's problems but not my own!) Otherwise, please complete your code to provide a small, compilable document people can play with. Start with \documentclass and end with \end{document}. Makes it much easier not only to help at all, but to help effectively! – cfr Sep 11 '14 at 18:42
• actually I used \titulo, but, I don't know why I translated it to english for posting it – JoseMiguel Sep 11 '14 at 18:45
• That makes sense. I often do something similar e.g. use \teitl which pretty much assures no clashes other than any of my own creation! – cfr Sep 11 '14 at 20:17

Here is a solution with titlesec, based on the examples in the package documentation around p. 22.

I put the section style in a macro so you can change it more easily. The arguments to \titleformat, as far as I can tell, do the following in order:

1. Determine which type of heading to format (here, \section)
2. Insert commands before the section number is typeset (here, the starting rule and font commands). In the example there is no section number because we call \section*, following the MWE.
3. Control how the section number is displayed (you could add a punctuation mark here, for example \thesection.)
4. Control the amount of horizontal space following the section number
5. Insert commands before the section title is typeset (here, the font commands again)
6. The last argument in brackets inserts commands after the section title is typeset (the bottom rule)

The spacing before and after the rule can be modified also.

\documentclass{article}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{titlesec}

\newcommand{\sectionfont}{\Large\bfseries}

\titleformat{\section}
{\titlerule
\vspace{0.5ex}%
\sectionfont}
{\thesection}{1em}
{\sectionfont}[\titlerule]

\begin{document}

Some results

\section*{Discusión y Análisis}

Some analysis

\end{document}


Really this is easiest with the titlesec package. For example:

\titleformat{\section}[block]
{\thesection\enspace}{0pt}{}[\vspace{2pt}\titlerule]


will redefine \section to be a heading of 14pt in bold (the 16pt is the baseline skip, it should not be set to 0) with rule above and below. The numberless version is then produced with \section*.

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{titlesec}
\titleformat{\section}[block]
{\thesection\enspace}{0pt}{}[\vspace{2pt}\titlerule]

\usepackage{lipsum} %For dummy text

\begin{document}

\lipsum[1]

\section*{Discusión y Análisis}
\lipsum[2]

\section{Discusión y Análisis}
\lipsum[2]

\end{document}


Note that you could define a numberless command \section by replacing {\thesection\enspace} by {} in the above definition, but you will get surprises if you then add a table of contents.

• What if you wanted the sections to be numbered though? – Zack Fair May 22 '17 at 23:11
• @FahimAbdullah Answer updated to show this. – Andrew Swann May 23 '17 at 7:13

Solved it using

\newcommand{\titulo}[1]
{
\par\noindent\rule{\linewidth}{0.8pt}\\[3pt]
\noindent{\Large\textbf{#1}}\\[-18pt]
\par\noindent\rule{\linewidth}{0.8pt}
}

• It would be nice, especially for future users of the site who might have the same problem as you, if you turned this answer into a complete MWE and explained how this solved the problem. – Adam Liter Sep 11 '14 at 19:58