# Center text in color box

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

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.

• 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 Sep 7 '14 at 22:02
• Tried putting \hfill <stuff> \hfill in your tcolorbox? – 1010011010 Sep 7 '14 at 22:03
• @1010011010: There is no tcolorbox information given... – user31729 Sep 7 '14 at 22:08

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

• @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. – David Carlisle Sep 7 '14 at 22:30