6

I want to write this form of sentence,

text1                text2

in the same sentence in the first page of my report. I tried to use flushleft and I right, but I got every text in a different sentence, like this:

text1
                               text2

I used these instructions:

begin{flushleft}
\textbf{text1}
\begin{flushright}
\textbf{text2}
\end{flushright}
\end{flushleft}

How do I fix it?

  • 1
    Welcome to TeX.SE! It seems that you like to have something like this text1 \hfill text2 ... – Zarko Jun 4 '16 at 13:05
  • Welcome to TeX.SX! Your example is not compilable. – user31729 Jun 4 '16 at 13:06
  • 1
    Sentences or single words? If the former, can you give a more extensive example? – egreg Jun 4 '16 at 13:27
10

Like this? (The showframe package is only to show the alignment, just remove it for production run)

The flushleft or flushright environments introduce some vertical spacing each time, this is cause for the two different lines!

Use \hfill for easy cases, or a tabular, for more complicated setups, (i.e. line wrapping etc., which is quite likely if 'sentences' are to be used instead of short words)

\documentclass{article}

\usepackage{showframe}

\begin{document}
\noindent
\textbf{text1}
\hfill
\textbf{text2}

\end{document}

enter image description here

Update, with some wrapping for sentences

\documentclass{article}
\usepackage{tabularx}

\usepackage{ragged2e}
\usepackage{showframe}

\usepackage{array}
\newcolumntype{Y}{>{\RaggedLeft\arraybackslash}X}

\newcommand{\sentenceleftright}[2]{%
  \begin{tabularx}{\textwidth}{@{}X@{}c@{}Y@{}}
    #1 & & #2\\
  \end{tabularx}%
}

\begin{document}
\parindent=0em
\textbf{text1}
\hfill
\textbf{text2}
\sentenceleftright{left}{right}
\sentenceleftright{And now (at last but not least) for something}{really really really really completely different}

\end{document}

enter image description here

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.