Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to somehow align section headings: unnumbered should be centerized; numbered should be aligned left and indented. I'm just trying to compile an example

\documentclass[12pt,a4paper,oneside]{article}
\usepackage[left=35mm,right=15mm,top=2cm,bottom=2cm,bindingoffset=0cm]{geometry}
\usepackage[utf8x]{inputenc}
\usepackage[russian]{babel}

\usepackage{cmap}

\usepackage{makeidx}
\makeindex

\usepackage{indentfirst}
\setlength{\parindent}{1.25cm}

\usepackage{setspace}
\onehalfspacing

\usepackage{titlesec}

\titleformat{\section*}{\normalfont\Large\bfseries\justifyheading}{\thesection}{1em}{}

\begin{document}
    \section*{РЕФЕРАТ}
\end{document}

But I'm getting

! Missing \endcsname inserted.
! LaTeX Error: Missing \begin{document}.
! Extra \endcsname.
! Argument of \ttl@assign@i has an extra }.
! Paragraph ended before \ttl@assign@i was complete.
! Package keyval Error: \let \reserved@d =*\def \par .
! Missing \endcsname inserted.
! Missing number, treated as zero.
! Illegal unit of measure (pt inserted).
! Undefined control sequence.
! Missing number, treated as zero.
! Illegal unit of measure (pt inserted).
! Extra \endcsname.
! Undefined control sequence.
! Too many }'s.
! LaTeX Error: Command \CYRA unavailable in encoding OT1.

And - yes - is there a way to ONLY align sections not redefining a whole style? Should I use \newcommand instead and insert it in EVERY section?

share|improve this question
    
What do you mean by "align a section"? –  Werner Jun 13 '12 at 23:40
    
I want to centerize \section* title and make an indentation for \section title. –  efpies Jun 13 '12 at 23:42
    
Should the change apply only to unnumbered sections or shoud it also affect numbered sections? –  Gonzalo Medina Jun 13 '12 at 23:44
    
@GonzaloMedina Unnumbered should be centerized. Numbered should be aligned left and indented. –  efpies Jun 13 '12 at 23:46
    
@efpies please add this information to your original question. Please see my updated answer. –  Gonzalo Medina Jun 13 '12 at 23:49
add comment

1 Answer

up vote 4 down vote accepted

There's no \justifyheading command; you can use \filcenter instead; since different formatting will be applied to numbered and unnumbered sections, you can use the options name=\section,numberless in the first argument of \titleformat for unnumbered sections, and just \section for numbered sections. The explicit option was used to have explicit access to the title and to easily achieve the required indentation for numbered sections:

\documentclass[12pt,a4paper,oneside]{article}
\usepackage[left=35mm,right=15mm,top=2cm,bottom=2cm,bindingoffset=0cm]{geometry}
\usepackage[utf8x]{inputenc}
\usepackage[russian]{babel}

\usepackage{cmap}

\usepackage{makeidx}
\makeindex

\usepackage{indentfirst}
\setlength{\parindent}{1.25cm}

\usepackage{setspace}
\onehalfspacing

\usepackage[explicit]{titlesec}

\titleformat{\section}
  {\normalfont\Large\bfseries}{}{0em}{\hspace{1.25cm}\thesection\hspace{1em}#1}% numbered sections
\titleformat{name=\section,numberless}
  {\normalfont\Large\bfseries\filcenter}{}{0em}{#1} % unnumbered sections

\usepackage{lipsum} % just to generate text

\begin{document}
    \section*{РЕФЕРАТ}
    \section{РЕФЕРАТ}
\lipsum[1-2]
\end{document}

enter image description here

share|improve this answer
    
Ok, it works for the \section, but doesn't work for \section*... –  efpies Jun 13 '12 at 23:44
    
@efpies please see my edited answer. –  Gonzalo Medina Jun 13 '12 at 23:45
    
Thanks, it works! And how I can indent a numbered section (with the number) by value defined in \parindent? –  efpies Jun 13 '12 at 23:55
1  
You will have to use something like \titleformat{\subsection} {\normalfont\large\bfseries}{}{0em}{\hspace{1.25cm}\thesubsection\hspace{1em}#1}‌​ \titleformat{name=\subsection,numberless} {\normalfont\Large\bfseries\filcenter}{}{0em}{#1}. –  Gonzalo Medina Jun 14 '12 at 1:03
2  
@efpies yes, #1 controls the title and \thesubsection gives the counter. –  Gonzalo Medina Jun 14 '12 at 1:05
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.