# Problems with centering

I define the command

\newcommand{\rec}[2]{\begin{center}
{\fboxsep 8pt
\fcolorbox{RoyalBlue4}{LightYellow2}{
\begin{minipage}[t]{15cm}
\textcolor{RoyalBlue4}{\large{\textsf{\bf #1}}}\\
#2
\end{minipage}}}
\end{center}}


But When I used it wih centerings fails, for example, if I type

\rec{a}{\begin{center}
b
\end{center}}


No problems here, but when I type

\rec{\begin{center}
a
\end{center}}{b}


Fails. Can you say me the problem?

-
Use \color{RoyalBlue4} (only one argument) instead of \textcolor. –  egreg Mar 4 '13 at 15:03
I changed it but the problem persists –  Diego Silvera Mar 4 '13 at 15:14

There's a problem with \\, but you really want \par there.

\documentclass{article}
\usepackage[svgnames,dvipsnames]{xcolor}
\newcommand{\rec}[2]{\begin{center}
\setlength{\fboxsep}{8pt}%
\fcolorbox{RoyalBlue}{LightYellow}{%
\begin{minipage}[t]{15cm}
\textcolor{RoyalBlue}{\large\sffamily\bfseries #1}\par
#2
\end{minipage}%
}
\end{center}%
}
\begin{document}
\rec{a}{\begin{center}b\end{center}}

\rec{\begin{center}a\end{center}}{b}

\end{document}


I changed the colors, because I don't know how yours were defined.

Notice that \large doesn't take an argument and that \bf is an obsolete command (you probably noticed that you didn't get sans serif type with it).

-
Thanks, but the \color{RoyalBlue} continues until the end. –  Diego Silvera Mar 4 '13 at 20:29
@DiegoSilvera Sorry, I lost track of braces; fixed. –  egreg Mar 4 '13 at 20:44
I can put \vspace{-0.5cm} before a \begin{center} to avoid the vertical space, but there is some way to avoid it. Thanks. –  Diego Silvera Mar 4 '13 at 21:03
@DiegoSilvera Use \centering: \rec{a}{\centering b} –  egreg Mar 4 '13 at 21:14

In the second case the error message is "There is no line here to end", which means you are in vertical mode.

Try:

\documentclass{article}
\usepackage[x11names]{xcolor}

\newcommand{\rec}[2]{\begin{center}
{\fboxsep 8pt
\fcolorbox{RoyalBlue4}{LightYellow2}{
\begin{minipage}[t]{15cm}
%\textcolor{RoyalBlue4}{\large{\textsf{\bf #1}}}%
{\color{RoyalBlue4}\large\bfseries\textsf{#1}}%
\ifhmode\expandafter\\\fi
#2
\end{minipage}}}
\end{center}}

\begin{document}
\rec{a}{\begin{center}
b
\end{center}}

\rec{\begin{center}
a
\end{center}}{b}
\end{document}


after improving a bit on the OP's code:

-
+1, but you probably want to change \bf into \bfseries: as you can see, the text is not in sans serif type. However, I think that \color{...} is preferable when the text to typeset is complex. –  egreg Mar 4 '13 at 15:26
@egreg agreed . –  user700902 Mar 4 '13 at 15:28