I made this LaTeX function:
\newcommand{\Hrule}[2]{\vspace{#1}\hrule\vspace{#2}}
Now, I'd like to edit this function in this way: I want add a #3 in whose specify the color of this \Hrule
.
And I want add a #4 to declare the thickness of \hrule
.
Is it possible?
For example if I write \Hrule{2mm}{2mm}{red}{2.5mm}
I would obtain a red \hrule
… .
Must I provide a minimum MWE?
Thank you so much.
Best Answer
You should use
\par\addvspace
rather than\vspace
at the beginning.Next, you can start a group to set the color. The default value of the optional argument is
.
that inxcolor
stands for the current color.If you want to add another argument to set the thickness you can do
However, using four arguments is error prone, so I suggest a key-value based approach.
The output is the same as in the previous picture.
Comparison between my solution and Sergio Llorente's
You can see that the amount of spacing with my solution is exactly what's requested.