Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have two lines of text written in Lyx. I'm trying to center it without placing extra vertical space between lines.

I selected the text, then went to Menu > Edit > Paragraph Settings. There, I can either remove spacing between lines or center the lines. But I can't do both of it at the same time.

The codes generated by Lyx are below for both two cases.

Centered, but there is space between lines:

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=1cm,bmargin=1cm,lmargin=1cm,rmargin=1cm,headheight=0cm,headsep=0cm,footskip=0cm}
\pagestyle{empty}
\setlength{\parskip}{0bp}
\setlength{\parindent}{0pt}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{babel}
\begin{document}

\noindent \begin{center}
Hello
\par\end{center}

\noindent \begin{center}
World
\par\end{center}

There is no space, but not centered either:

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=1cm,bmargin=1cm,lmargin=1cm,rmargin=1cm,headheight=0cm,headsep=0cm,footskip=0cm}
\pagestyle{empty}
\setlength{\parskip}{0bp}
\setlength{\parindent}{0pt}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{setspace}
\usepackage{babel}
\begin{document}

\begin{singlespace}
\noindent Hello

\noindent World
\end{singlespace}

Looking at these sources, I can feel that it should have been something like

\begin{singlespace}
\noindent \begin{center} Hello \end{center}
\noindent \begin{center} World \end{center}
\end{singlespace}

but as you know, user is not allowed to edit the source directly in Lyx.

How do I do it in proper way?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

Write the first line, hit Ctrl + Enter (this adds a line break), and type the second line. To center align that paragraph, right click one of the lines, choose Paragraph settings, and select Center alignment.

For reference, this generates the markup in David's last example.

share|improve this answer
add comment

The other answer has addressed the lyx input but

\begin{singlespace}
\noindent \begin{center} Hello \end{center}
\noindent \begin{center} World \end{center}
\end{singlespace}

Any use of \noindent within a document is a sign that something is wrong and the layout implemented by the document class is not suitable for the content.

But using \noindent before a display environment like center is just wrong: it will have no affect on the indentation of the content of the environment; it will just generate a spurious empty paragraph before the environment and so give the appearance of increasing the vertical space before the environment. Because it is a blank line rather than vertical space, it will not, for example, be discarded at a page break.

The markup that you want to generate is

\begin{center}
Hello

World
\end{center}

or

\begin{center}
Hello\\
World
\end{center}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.