34

I would like to center a horizontal line on my page and I would like the width of this line to be half \textwidth. Here is what I tried but it doesn't work :

\documentclass[10pt,a4paper]{article}
\begin{document}

Hello everyone ! 

\begin{center}
\hrule width 0.5\textwidth
\end{center}

\end{document}

Thank you for your help !

5
  • \rule{0.5\textwidth}{0.5pt}? Commented Aug 17, 2013 at 9:16
  • BTW: Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Commented Aug 17, 2013 at 9:17
  • 1
    @karlkoeller \rule{0.5\textwidth}{0.4pt} is a better equivalent to \hrule.
    – lockstep
    Commented Aug 17, 2013 at 9:18
  • Thanks for your comment but it seems it doesn't produce a line centered on the page.
    – pitchounet
    Commented Aug 17, 2013 at 9:19
  • @lockstep Yes, you're right, 0.4pt is the exact equivalent, according to the TeXbook. Commented Aug 17, 2013 at 9:59

2 Answers 2

51

You can replace

\hrule width 0.5\textwidth

with

\rule{0.5\textwidth}{.4pt}

Also, if you don't need the center environment for anything else, you can replace

\begin{center}
\rule{0.5\textwidth}{.4pt}
\end{center}

with simply

\noindent\hfil\rule{0.5\textwidth}{.4pt}\hfil

MWE

\documentclass[10pt,a4paper]{article}
\begin{document}

Hello everyone !

\begin{center}
\rule{0.5\textwidth}{.4pt}
\end{center}

\noindent\hfil\rule{0.5\textwidth}{.4pt}\hfil

\end{document} 

Output

enter image description here

0
0

I tried using \rule in the accepted answer, but I ended up going with \hrule like the original question asked too:

\newcommand{\SectionBreak}{%
    %\vskip 0.5ex

    \nointerlineskip
    \moveright 0.125\textwidth \vbox{\hrule width0.75\textwidth}
    \nointerlineskip
    %\vskip 0.5ex
    \makeatletter
        %\@afterindenfalse%
    \makeatother

}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .