# Centering with tabularx and minipage

I'm still new to LaTeX, and I have a litle problem, I have a table with 3 columns and one row, the first and last column are equal, and the middle take all the space. But I want to center content of it. When I use \centering I got the result in the image bellow. Is there any solution?

    \begin{table}
\begin{tabularx}{\linewidth}{|m{3cm}|X|m{3cm}|}
\hline

\begin{minipage}{\textwidth}
\includegraphics[width=3cm, height=2.5cm]{ump.png}
\end{minipage}

&

\begin{minipage}{\textwidth}
\centering
Université Mohamed Premier \\
École Nationale de Commerce et de Gestion \\
Oujda. \\
\end{minipage}

&

\begin{minipage}{\textwidth}
\includegraphics[width=3cm, height=2.5cm]{ump.png}
\end{minipage}

\\ \hline
\end{tabularx}
\end{table}


Thank you very much.

• A quick fix: use \linewidth instead of \textwidth for the middle minipage – Troy May 5 '17 at 10:44
• you don't need any of the minipages, just remove them, nor (I suspect) do you want the table environment – David Carlisle May 5 '17 at 10:46

    \documentclass[a4paper]{article}

\usepackage{tabularx}
\usepackage{graphicx}
\begin{document}

\begin{table}
\begin{tabularx}{\linewidth}{|m{3cm}|>{\centering\arraybackslash}X|m{3cm}|}

\hline
\includegraphics[scale=3.1]{2.png}
& \vspace*{-9mm}
Université Mohamed Premier\newline
Ecole Nationale de Commerce et de Gestion\newline
Oujda.
&
\vspace*{5mm}
\includegraphics[scale=3.1]{2.png}

\\ \hline

\end{tabularx}

\end{table}

\end{document}


• You're missing \usepackage[T1]{fontenc}. – Bernard May 5 '17 at 11:19

You do not need the inner minipage or the outer table environment. It is probably simpler not to use tabularx either.

\documentclass{article}

\usepackage{tabularx,graphicx}

\begin{document}

\noindent
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{tabularx}{\linewidth}{|m{3cm}|X|m{3cm}|}
\hline

\includegraphics[width=\linewidth]{example-image-a}

&

\centering
Université Mohamed Premier \\
École Nationale de Commerce et de Gestion \\
Oujda.

&

\includegraphics[width=\linewidth]{example-image-b}

\\ \hline
\end{tabularx}

\bigskip

But simpler you don't need a table at all

\bigskip

\noindent
\mbox{\includegraphics[width=2.5cm]{example-image-a}%
\hfill
\begin{tabular}[b]{c}
Université Mohamed Premier \\
École Nationale de Commerce et de Gestion \\
Oujda.
\end{tabular}%
\hfill
\includegraphics[width=2.5cm]{example-image-b}}

\end{document}

• Dear sir I am new to latex please let me know the use of \noindent, when i remove the \noindent the output is still the same @David Carlisle – Biki Teron May 5 '17 at 11:23
• oops I'm missing \usepackage[utf8]{inputenc} so the accented characters work. – David Carlisle May 5 '17 at 11:23
• @BikiTeron without \noindent the start of a paragraph (which is the first image here) is indented by \parindent (15pt in report class) – David Carlisle May 5 '17 at 11:24
• Sir can you please show with the figures so that i can make differentiate @David Carlisle, thanking you in advance. – Biki Teron May 5 '17 at 11:28
• @BikiTeron really you shouldn't ask unconnected questions as comments under an answer, just try it yourself: remove the first \noindent in the code I posted and tex's log will tell you Overfull \hbox (15.0pt too wide) in paragraph at lines 29--30 as the line will have been shifted 15pt to the right – David Carlisle May 5 '17 at 11:41

Use a simple tabular for each cell. This way, you get the logos vertically centered automatically as well as the text in the middle. You will also need a >{\centering} before the middle column to make it horizontally centered.

\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx,tabularx}
\usepackage[margin=1in]{geometry}
\begin{document}

\newcommand{\cell}[1]{\begin{tabular}{@{}c@{}}#1\end{tabular}}

\begin{table}
\begin{tabularx}{\linewidth}{|c|>{\centering}X|c|}
\hline
\cell{\includegraphics[scale=3]{logo.png}}
&
\cell{Université Mohamed Premier \\
École Nationale de Commerce et de Gestion\\
Oujda.}
&
\cell{\includegraphics[scale=3]{logo.png}} \\ \hline
\end{tabularx}
\end{table}

\end{document}


As I don't think this will have to float (looks like a header), I removed the table environment. Centring is obtained by redefining the X columntype and using the valign key from adjustbox:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{tabularx, cellspace}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{document}%

\begin{tabularx}{\linewidth}{|Sc|X|Sc|}
\noalign{\setlength{\cellspacetoplimit}{0pt}}
\hline