Text FormattingProblem with \newcommand and nested fontstyles

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
progressive
Posts: 3
Joined: Fri Apr 22, 2011 9:18 pm

Problem with \newcommand and nested fontstyles

Post by progressive »

Hello,

I am having trouble with creating a function - specifically nesting font formats within others.

For example, when I try to make a new function:

Code: Select all

\newcommand{secthead}[1]{{\center \Large \underline{#1}}}
MikTeX responds with the error

Code: Select all

! Missing number, treated as zero.
<To be read again>
             c
l.14 ...head[1]{\center \Large \underline{#1}}}
I'm not entirely sure what is wrong, since using the function I defined on its own seems to work fine.

Thanks for the help!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Re: Problem with \newcommand and nested fontstyles

Post by Stefan Kottwitz »

Hi,

there'a a backslash missing in the definition, it should be \secthead.

Stefan
LaTeX.org admin
progressive
Posts: 3
Joined: Fri Apr 22, 2011 9:18 pm

Problem with \newcommand and nested fontstyles

Post by progressive »

Hello again,

How embarrassing that I forgot the backslash...


However, I am still encountering a problem with using \secthead.

If I try

Code: Select all

{\secthead something}
then only the first letter, 's', is underlined, and the word is also left justified. To make matters worse, the text is not Large either.

When I try

Code: Select all

{\secthead{something}}
then the text is now Large and everything is underlined, but the text is still left justified! Is there a problem with my MikTeX, because I'm pretty sure this command should work properly...right?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Problem with \newcommand and nested fontstyles

Post by Stefan Kottwitz »

Hi,

\secthead requires an argument. If you write {\secthead something}, it takes the next letter as the argument. If you try {\secthead{something}}, it takes the expression in braces. This explains the different behavior.

Regarding the centering: use \begin{center} ... \end{center} or use \centering. See here regarding the difference: center vs. \centering.

Stefan
LaTeX.org admin
Post Reply