1

I have got a problem with tabularx: I want to have two images next to each other on the titlepage of a document. I use tabularx for that. My code is:

\begin{titlepage}
    \begin{tabularx}{\textwidth}{XX}
        \begin{flushleft}
            \vspace{0.6cm}  % adjust the vertical alignment of the images
            \includegraphics[height=1.3cm]{image1}
        \end{flushleft}
        &
        \begin{flushright}
            \includegraphics[height=2.5cm]{image2}
        \end{flushright}
    \end{tabularx}

    % other content of the titlepage

\end{titlepage}

My problem is, that on the left side the image is perfectly aligned at the left border, but on the right side the image is not positioned correctly. It is above the page margins and it looks as if the \begin{tabularx}{\textwidth} does not work.

It would be great if anybody could help me. Thanks in advance

jenald
  • 11
  • 2
  • 1
    Hi, welcome. Images are not resized just because they're inside a tabularx, so if the width of the images plus the column separation is wider than \textwidth, then the images will go into the right margin. – Torbjørn T. Sep 19 '17 at 10:37
  • 2
    tabularx can do nothing useful here, just use \includegraphics[height=1.3cm]{image1}\includegraphics[height=1.3cm]{image2} – David Carlisle Sep 19 '17 at 10:38
  • Also, add \noindent before \begin{tabularx}. – Bernard Sep 19 '17 at 10:40
  • the images are not larger than the page. There is some white space between them and i wanted to use tabularx to align them left and right – jenald Sep 19 '17 at 10:44
  • i tried the \noindent and i think it worked. What does it do generally? – jenald Sep 19 '17 at 10:45
  • Guess by its name. You are starting a paragraph, they are indented by default in latex – daleif Sep 19 '17 at 10:47
  • https://tex.stackexchange.com/questions/209993/how-to-customize-my-titlepage – Johannes_B Sep 19 '17 at 10:51
  • ok, I thought, I used parskip, but obviously I didn't. Thank you very much for your help, Bernard and daleif – jenald Sep 19 '17 at 10:51
  • Don't use the tabular, it is pointless to use it. – Johannes_B Sep 19 '17 at 10:52
  • ok, @Johannes_B, how can I then position them on the left and on the right side of the page but vertically centered? – jenald Sep 19 '17 at 10:58

2 Answers2

1

Echoing the earlier comments by David C. and Johannes B., your code may be simplified as follows -- observe that complete absence of tabularx, flushleft, and flushright environments:

\documentclass{article} 
\usepackage[demo]{graphicx} % omit 'demo' option in real document
\begin{document}
\begin{titlepage}

\noindent % <-- this is required
\includegraphics[height=1.3cm]{image1}\hspace{\fill}
\includegraphics[height=2.5cm]{image2}

% other content of the titlepage
\end{titlepage}
\end{document}

If the two graphs need to be centered vertically relative to one another, just encase the \includegraphics statements in separate minipage environments:

\documentclass{article} 
\usepackage[demo]{graphicx} % omit 'demo' option in real document
\begin{document}
\begin{titlepage}

\noindent
\begin{minipage}{0.5\textwidth}
\includegraphics[height=1.3cm]{image1}
\end{minipage}% % <-- the first "%" is important
\begin{minipage}{0.5\textwidth}
\raggedleft % shove stuff to right-hand edge of text block
\includegraphics[height=2.5cm]{image2}
\end{minipage}

% other content of the titlepage
\end{titlepage}
\end{document} 
Mico
  • 506,678
0

in the case that you still like use tabularx ...

\documentclass{article}
\usepackage[demo]{graphicx} % omit 'demo' option in real document
\usepackage{tabularx}

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}

\begin{titlepage}
% \renewcommand\tabularxcolumn[1]{m{#1}} % use in case when you like to have vertical centered images
\noindent % for table start at left text border
\begin{tabularx}{\textwidth}{@{}      % removed \tabcolsep on the left
                                X     % image flushed left 
   >{\raggedleft\arraybackslash}X     % image flushed right 
                             @{}}     % removed \tabcolsep on the right
\includegraphics[height=1.3cm]{image1}
    &
\includegraphics[height=2.5cm]{image2}
\end{tabularx}

% other content of the titlepage
\end{titlepage}

\end{document}

enter image description here

or when you activate \renewcommand\tabularxcolumn[1]{m{#1}}:

enter image description here

Zarko
  • 296,517