4

I wanto to center a text in a colorbox which is scaled horicontal over the complete site.

enter image description here

How is this possible?

\documentclass[
]{scrreprt}

\usepackage[
]{scrpage2}

\usepackage[ngerman]{babel}                 %% Deutsches Sprachpaket
\usepackage[utf8]{inputenc}                 %% Eingabezeichensatz UTF-8
\usepackage[T1]{fontenc}                    %% Kodierung für Umlaute
\usepackage[ngerman]{translator}            %% Für Abkürzungsverzeichnis benötigt
\usepackage{lmodern}                        %% Moderne Version von Computer Modern
\usepackage{setspace}                       %% Zeileabstand anpassen
\usepackage{xcolor}                         %% Definieren von Farben

\begin{document}

\chapter{}
\definecolor{lightgray}{gray}{0.5}
\newcommand \colbox [1]{\par\noindent\colorbox{gray}{\begin{minipage}{\textwidth}{ {#1}} \hfill \end{minipage}}}

\colbox{TEXT}

\end{document}

Moreover I want to avoid the overfull hbox.

3
  • Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – user31729
    Commented Sep 7, 2014 at 22:02
  • Tried putting \hfill <stuff> \hfill in your tcolorbox?
    – 1010011010
    Commented Sep 7, 2014 at 22:03
  • @1010011010: There is no tcolorbox information given...
    – user31729
    Commented Sep 7, 2014 at 22:08

1 Answer 1

4

You need a full width \parbox after taking account the padding added by \colorbox:

\noindent
\colorbox{grey}{\parbox{\dimexpr\textwidth-2\fboxsep}{\centering
 hello
}}
2
  • Is it possible to use \verbatim in the text section? Because I wanto to write a command there.
    – Martin
    Commented Sep 7, 2014 at 22:27
  • @Martin well not directly but there are several answers showing how to put verbatim in a box, but you presumably don't mean verbatim (as you can't center that as it is full width) if you just want a line such as in your question you don't need verb just \texttt{\$ git clone ...} would do. Commented Sep 7, 2014 at 22:30

You must log in to answer this question.

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