1

I want to ask your assistance in two commands(in latex .tex enviroment) thie first one needs a command which is called redbold, in this command I need form the text red colour and bold style. In the second one I need a command which is called centerit. In this case I need a center align and an italic style. Only the italic style is not working for me here. I hope someone could help me in this task. Have good day, and thanking you in advance for your assistance.

Here is my code:

\documentclass{article}
\usepackage{xcolor}
\definecolor{lb}{RGB}{44, 139, 183}
\newcommand\redbold[2]{\textcolor{#1}{{\fontseries{b}\selectfont #2}}}
\newcommand\centerit[2]{{\textit{}}\centering}
\begin{document}

\redbold{red}{red and bold}
\vspace{5em}


\centerit[]{center and italic}
\end{document}
2

Welcome to TeX.SE. Why did you declare your \centerit command to take two arguments but used none of #1 and #2 in the replacement text? Besides, you called it with an optional (empty) argument (plus a mandatory one), but you didn't use the syntax for defining a macro that takes an optional argument (that would be \newcommand{\centerit}[numargs][default]{replacement text}).

The following should do what you want, I hope:

\documentclass{article}
\usepackage{xcolor}
\definecolor{lb}{RGB}{44, 139, 183}

\newcommand{\redbold}[2]{%
  \textcolor{#1}{\fontseries{b}\selectfont #2}}

\newcommand{\centerit}[1]{%
  \par\begingroup\centering\itshape #1\par\endgroup
}

\begin{document}

\redbold{red}{red and bold}
\vspace{5em}

\centerit{center and italic}

\end{document}

enter image description here

| improve this answer | |
  • Thank you! I am sorry I am not good at this topic, it as an simple course in the university and I want to complete these homework like this. Respect for your assistance. I wish happy and healthy months for you. :) – ultimate warrior Mar 27 at 21:53
  • Don't be sorry, I'm glad I could be of assistance... but I hope I didn't do your homework! :-p Thanks for the kind words, I wish you a good health too in these dark days! – frougon Mar 27 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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