# Tables with fixed column widths and language switching

I'm trying to typeset a German-Slovak vocabulary list and some grammar. Since table entries might get long, I'm using tables with p-columns. For correct hyphenation, I want to switch to Slovak in the respective column using babel. In order to do this, I defined

\newcommand{\slk}[1]{\selectlanguage{slovak}#1\selectlanguage{ngerman}}


which switches to Slovak and back to German afterwards. However, if the table is coded with a tabular-environment, there are extra linebreaks in the right column. If I do the same with longtable, no extra linebreaks occur. Is there a way to fix the tabular issue?

\documentclass{article}
\usepackage[T2A,T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage[slovak,ngerman]{babel}
\usepackage{droid}
\usepackage{tipa}
\usepackage{array,longtable}
\newcommand{\slk}[1]{\selectlanguage{slovak}#1\selectlanguage{ngerman}}
\begin{document}
\begin{center}
\begin{tabular}{|p{2cm}|p{2cm}|}
Nom.&\slk{môj, tvoj, náš, váš}\\
Gen.&\slk{-ho}
\end{tabular}
\begin{longtable}{|p{2cm}|p{2cm}|}
Nom.&\slk{môj, tvoj, náš, váš}\\
Gen.&\slk{-ho}
\end{longtable}
\end{center}
\end{document}


The symptoms are quite similar to Creating table using tabularx and datatool from csv file but NoHyper environments do not fix my issue. (Yes, hyperref will be in my final document, too.)

• Welcome to TeX.SX! I'd define \newcommand{\slk}[1]{\foreignlanguage{slovak}{#1}} Feb 27 '15 at 9:26

Explicit usage of \selectlanguage in a document should be very rare.

In your case the correct command to use is \foreignlanguage:

\documentclass{article}
\usepackage[T2A,T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage[slovak,ngerman]{babel}

\usepackage{droid}
\usepackage{tipa}
\usepackage{array,longtable}

\newcommand{\slk}[1]{\foreignlanguage{slovak}{#1}}

\begin{document}

\begin{center}
\begin{tabular}{|p{2cm}|p{2cm}|}
Nom.&\slk{môj, tvoj, náš, váš}\\
Gen.&\slk{-ho}
\end{tabular}
\end{center}

\begin{longtable}{|p{2cm}|p{2cm}|}
Nom.&\slk{môj, tvoj, náš, váš}\\
Gen.&\slk{-ho}
\end{longtable}

\end{document}


Note that longtable is centered by default. Also I'd not use utf8x, but utf8.