General\begin{center} does not really center text

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
wildeskraut
Posts: 3
Joined: Sat Dec 11, 2010 1:11 pm

\begin{center} does not really center text

Post by wildeskraut »

I am writing a text and need a covering page, using \begin{center} causes a problem. I use it for two lines and only one of them is really centred.

Here is my code:

Code: Select all

\begin{center}
\begin{Large}
\vfill {\textsf{\textbf{
China und Afrika \\ {\large Oliver Söder}
}}}

\end{Large}
\end{center}
Here is the code of the whole covering page:

Code: Select all

%Einfache Vorlage für eine mit Latex realisierte Hausarbeit von http://www.studieren-info.de
%Du kannst diese Vorlage für deine Hausarbeit beliebig anpassen%


%-------------------
%Beginn des Kopfbereiches
%-------------------

%Wir verwenden eine DIN-A4-Seite und die Schriftgrösse 12.
\documentclass[a4paper,12pt]{scrartcl} 


%Diese drei Pakete benötigen wir für die Umlaute, Deutsche Silbentrennung etc.
\usepackage[latin1]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{picins}					%Auch um Bilder von Text umfließen zu lassen

%Notlösung aus Unwissenheit, das Wort HTWG in weiss schreiben, damit Titel horizontal zentriert ist
\usepackage{color}
\newcommand{\WeisseSchriftaufweissemPapier}{\color{white}}

%Das Paket erzeugt ein anklickbares Verzeichnis in der PDF-Datei.
%\usepackage{hyperref}

%Das Paket wird für die anderthalb-zeiligen Zeilenabstand benötigt
\usepackage{setspace}

%Einrückung eines neuen Absatzes
\setlength{\parindent}{0em}

%Definition der Ränder
\usepackage[paper=a4paper,left=25mm,right=25mm,top=30mm,bottom=30mm]{geometry} 

%Abstand der Fussnoten
\deffootnote{1em}{1em}{\textsuperscript{\thefootnotemark\ }}

%Regeln, bis zu welcher Tiefe (section,subsection,subsubsection) Überschriften angezeigt werden sollen (Anzeige der Überschriften im Verzeichnis / Anzeige der Nummerierung)
\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}

%-------------------
%Ende des Kopfbereiches
%-------------------


%-------------------
%Hier beginnt der Text deiner Hausarbeit
%-------------------
\begin{document}

%Beginn der Titelseite
\begin{titlepage}

%Notlösung aus Unwissenheit, das Wort HTWG in weiss schreiben, damit Titel horizontal zentriert ist
\begin{small}
\vfill {\WeisseSchriftaufweissemPapier HTWG Konstanz}
\end{small}


\begin{center}
\begin{Large}
\vfill {\textsf{\textbf{
China und Afrika \\ {\large Hans Mayer}
}}}

\end{Large}
\end{center}

\begin{small}

\vfill XX YY\hfill Greater China \\ 0178/11111 \hfill Prof. Dr. XXX \\  
yyyy@htwg-konstanz.de \hfill XXX 4 \\ \today \hfill WS 2010/2011
%\today

\end{small}

\end{titlepage}
%Ende der Titelseite


%Inhaltsverzeichnis (aktualisiert sich erst nach dem zweiten Setzen)
\tableofcontents
\thispagestyle{empty}

%Seitenzahl soll erst nach dem Inhaltsverzeichnis gezählt werden
\newpage
\setcounter{page}{1}

%Beginn einer neuen Seite
%\clearpage

%Anderthalbzeiliger Zeilenabstand ab hier
\onehalfspacing
%Alternativ kann man direkt die pt-Grösse angeben
%\baselineskip18pt

\pagestyle{plain}

\section{Einleitung}
You can also watch the PDF output:
http://www.as2009.de/upload/Zhu4.pdf

I am talking about the name Hans Mayer, which is not really centred (or is it the headline "China in Afrika"?).

Thank you for your help.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

\begin{center} does not really center text

Post by sommerfee »

Please reduce your example next time before posting. Otherwise many people will decide not to look at your problem because it's too much code and because code reducing is the very first step examining the problem anyway.

Here is a minimal but complete example showing your problem:

Code: Select all

\documentclass[a4paper,12pt]{scrartcl}
\begin{document}
\begin{titlepage}

\begin{center}
\begin{Large}
\vfill {\textsf{\textbf{
China und Afrika \\ {\large Hans Mayer}
}}}

\end{Large}
\end{center}

\end{titlepage}
\end{document}
The reason why the two lines will not look exactly centered is the extra space they contain. So the problem can be solved by eliminating this space:

Code: Select all

\documentclass[a4paper,12pt]{scrartcl} 
\begin{document}
\begin{titlepage}

\begin{center}
\begin{Large}
\vfill {\textsf{\textbf{%
China und Afrika \\ {\large Hans Mayer}%
}}}

\end{Large}
\end{center}

\end{titlepage}
\end{document}
HTH,
Axel
Last edited by sommerfee on Sat Dec 11, 2010 2:25 pm, edited 1 time in total.
wildeskraut
Posts: 3
Joined: Sat Dec 11, 2010 1:11 pm

\begin{center} does not really center text

Post by wildeskraut »

Hello Alex,

it did not solve this problem, it is still same like before.

The name "Hans Mayer" is centered when I put it like that:

Code: Select all

\documentclass[a4paper,12pt]{scrartcl}
\begin{document}
\begin{titlepage}

\begin{center}
\begin{Large}
\vfill {\textsf{\textbf{
China und Afrika \\ {\large ....Hans Mayer}
}}}

\end{Large}
\end{center}

\end{titlepage}
\end{document}
How can I add four white spaces there?

Thank you
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

\begin{center} does not really center text

Post by sommerfee »

wildeskraut wrote:it did not solve this problem, it is still same like before.
Could you please upload the pdf file generated when compiling my second example code? (I just uploaded mine where you can see that the centering is correct.)
The name "Hans Mayer" is centered when I put it like that:
That's because all the extra spaces in your statement:

Code: Select all

\vfill {\textsf{\textbf{
China und Afrika \\ {\large ....Hans Mayer}
}}}
There is one extra space before "China und Afrika" and one extra space after "Hans Mayer". Both spaces are causing the misalign so eliminating the extra space should help. Please take a closer look at the differences between my first and my second example code.
Attachments
test.pdf
(10.47 KiB) Downloaded 493 times
wildeskraut
Posts: 3
Joined: Sat Dec 11, 2010 1:11 pm

\begin{center} does not really center text

Post by wildeskraut »

Hello Axel,

belief me, I tried your solution.

I took a ruler and found that it is not centered perfectly as well.

I am using this workaround now, which prints those three dots as white dots on white paper:

Code: Select all

\vfill {\textsf{\textbf{
China und Afrika\\{\large {\WeisseSchriftaufweissemPapier ...}Oliver Söder}
As I always use this template, I am thankfull when you help me to solve this matter properly, but right now I am a little bit in a hurry, as I need to finish this work quick :-(
But after that, I will be happy to try your suggestions again (will be next week).

Thank you a lot for your time!
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

\begin{center} does not really center text

Post by frabjous »

Is this better?

Code: Select all

\begin{center}
\begin{Large}%
\textsf{\textbf{China und Afrika}}%
\end{Large}

\begin{large}%
\textsf{\textbf{Hans Mayer}}%
\end{large}
\end{center}
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

\begin{center} does not really center text

Post by sommerfee »

wildeskraut wrote:I took a ruler and found that it is not centered perfectly as well.
If I take the PDF I have uploaded (test.pdf), print it out and take a ruler as well, I see "Hans Mayer" is perfectly centered below "China und Afrika". If this is not the case when you print my PDF, your printer driver seems to be broken. What happens if you take my PDF and use the ruler on the display instead?

Code: Select all

\vfill {\textsf{\textbf{
China und Afrika\\{\large {\WeisseSchriftaufweissemPapier ...}Oliver Söder}
I'm sorry, but I still don't understand why you are not removing the extra spaces here. Even if the result is not perfect afterwards at your computer (for what strange reason ever), it's crystal clear that a space leading "China und Afrika" and a space trailing "Oliver Söder" is not helpful for getting a correct centering.
Post Reply