LyXCentering a Section Heading using LaTeX Code

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
Post Reply
newclear
Posts: 1
Joined: Sat May 19, 2012 3:52 am

Centering a Section Heading using LaTeX Code

Post by newclear »

LyX is giving me the following error when I try to use LaTeX code to center a section title. It is not for every section title that I try and center, I have two that work but the others I can't. The image posted is what I have written in LyX.
LyX-CenterSection.png
LyX-CenterSection.png (9.48 KiB) Viewed 23524 times

Code: Select all

Errors: LaTeX Error: Something's wrong—perhaps a missing \item.
Description: \end{center}
I'm confused and can't figure out the problem. Google has pulled up no solutions either. Any help is appreciated.

Thanks.
Last edited by localghost on Sat May 19, 2012 10:00 am, edited 1 time in total.

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

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

Centering a Section Heading using LaTeX Code

Post by cgnieder »

You can't put the {center} environment around a section title.

If you're using a KOMA-Script class like scrartcl the easiest way is to say \let\raggedsection\centering

Code: Select all

\documentclass{scrartcl}

\let\raggedsection\centering

\begin{document}
\section{The Babel Fish}
``The Babel fish,'' said The Hitchhiker's Guide to the Galaxy quietly, ``is small,
yellow and leech-like, and probably the oddest thing in the Universe. It feeds on
brainwave energy received not from its own carrier but from those around it. It
absorbs all unconscious mental frequencies from this brainwave energy to nourish
itself with. It then excretes into the mind of its carrier a telepathic matrix
formed by combining the conscious thought frequencies with nerve signals picked
up from the speech centres of the brain which has supplied them. The practical
upshot of all this is that if you stick a Babel fish in your ear you can instantly
understand anything in any form of language. The speech patterns you actually hear
decode the brainwave matrix which has been fed into your mind by your Babel fish.

\end{document}
If you're using one of the standard classes you can use titlesec to define a centered section format:

Code: Select all

\documentclass{article}

\usepackage{titlesec}
\titleformat{\section}[block]{\sffamily\Large\bfseries\filcenter}{\thesection}{1em}{}


\begin{document}
\section{The Babel Fish}
``The Babel fish,'' said The Hitchhiker's Guide to the Galaxy quietly, ``is small,
yellow and leech-like, and probably the oddest thing in the Universe. It feeds on
brainwave energy received not from its own carrier but from those around it. It
absorbs all unconscious mental frequencies from this brainwave energy to nourish
itself with. It then excretes into the mind of its carrier a telepathic matrix
formed by combining the conscious thought frequencies with nerve signals picked
up from the speech centres of the brain which has supplied them. The practical
upshot of all this is that if you stick a Babel fish in your ear you can instantly
understand anything in any form of language. The speech patterns you actually hear
decode the brainwave matrix which has been fed into your mind by your Babel fish.

\end{document}
Regards
site moderator & package author
Post Reply