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?



\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


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



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:

| improve this answer | |
  • Is it possible to use \verbatim in the text section? Because I wanto to write a command there. – Martin Sep 7 '14 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. – David Carlisle Sep 7 '14 at 22:30

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.