2

I currently have a simple colorbox, I would like to increase its height. Is there a way to set a fixed height, or maybe a kind of padding? I added \hspace to add some space horizontally, but a \vspace has no effect.

I have package xcolor imported.

It is currently in a minipage as I want this text to be next to a logo. I am relatively new to LaTeX, there might beginner errors.


\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myclass}
\LoadClass[11pt,a4paper,final]{memoir}

\RequirePackage{xcolor}
\RequirePackage[pdftex]{graphicx}

...

\renewcommand{\maketitle}{
    \begin{minipage}{0.45\textwidth}
        \includegraphics{logo}
    \end{minipage}
    \begin{minipage}{0.45\textwidth}
        \raggedleft
        \colorbox{red}{
            \hspace{0.5cm}
            {\color{white}\large My text }
            \hspace{0.5cm}
        }
    \end{minipage}
}
1
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Aug 12, 2019 at 14:08

1 Answer 1

2

You can fix the height by inserting a \vphantom\ with the value you request for the height. In my example, I set the height to 2.5 cm.

The code for \hz is adapted from Yiannis Lazarides code in this answer.

enter image description here

\documentclass[demo]{article}
\usepackage{xcolor}
\usepackage{graphicx}
\newcommand{\hz}{\vphantom{\parbox[c]{1cm}{\rule{1cm}{2.5cm}}}}

\begin{document}

\begin{minipage}{0.45\textwidth}
    \includegraphics{logo}
\end{minipage}
\begin{minipage}{0.45\textwidth}
    \raggedleft
    \colorbox{red}{%
         \hz
         \hspace*{0.5cm}%
        {\color{white}\large My text }%
         \hspace*{0.5cm}%
    }
\end{minipage}
\end{document}
2
  • don't use \def, use \newcommand. Aug 12, 2019 at 14:48
  • @UlrikeFischer As I said, I copied the code from another answer, and taken into account who wrote the answer, I assumed \def was safe. However, I will change to \newcommand.
    – Sveinung
    Aug 12, 2019 at 16:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .