Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 895643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:35:31+00:00 2026-05-15T14:35:31+00:00

In LaTeX, I’m using the listings package to display some code snippet inside a

  • 0

In LaTeX, I’m using the listings package to display some code snippet inside a table. But it seems that when using this package, the vertical alignement of the cells is changing.

Here is some code :

\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern,textcomp}
\usepackage[frenchb]{babel}
\usepackage{listings}

\begin{document}
\begin{tabular}{ll}
\hline Méthode & Exemple d'utilisation\\
\hline isLetter()&
\begin{lstlisting}
QChar MyChar('x');
bool IsLetter = MyChar.isLetter();
// IsLetter vaut vrai
// bla bla bla
\end{lstlisting}\\
\hline
\end{tabular}
\end{document}

and here is what I get (notice the centered vertical alignement of the first column) :

http://img820.imageshack.us/img820/8509/image4l.png.

If I avoid using the listings package inside the table, the vertical alignement is different (centered) :

\begin{tabular}{lp{5cm}}
\hline Méthode & Exemple d'utilisation\\
\hline isLetter()&
QChar MyChar('x');
bool IsLetter = MyChar.isLetter();
// IsLetter vaut vrai
// bla bla bla
\\
\hline
\end{tabular}

http://img691.imageshack.us/img691/8585/image5gy.png.

What I would like is to put some code inside the table but keep the vertical alignement to top for the cells.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:35:31+00:00Added an answer on May 15, 2026 at 2:35 pm

    Tell latex to align it at the top of the baseline of its textline by the option boxpos.

    \begin{lstlisting}[boxpos=t]
    QChar MyChar('x');
    bool IsLetter = MyChar.isLetter();
    // IsLetter vaut vrai
    // bla bla bla
    \end{lstlisting}
    

    The problem also happens with other boxes

    \parbox[t]{3cm}{Hello\\World\\Peace}
    \parbox[t]{3cm}{Goodbye}
    

    If you leave out the position parameter t, it will align both boxes centered relative to each other.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using LaTeX , I need to show some code snippet inside a table. Here
I'm using LaTeX 's listings package to format source code. Unfortunately I get curly
I use latex to typeset lots of code using the minted package. Mainly the
I am using this: latex(data, cgroup=c(sample1, sample2), n.cgroup=c(2,2), file=) to generate a tex table.
I'm new to latex, but it seems you can temporarily redefine some commands? The
I'm a LaTeX beginner. Up until now whenever I've created a table (using the
I'm using Latex to write a program listing all my code and I am
I have LaTeX code inside PHP (not as .tex file); for example received by
In my LaTeX document I've got a table of contents that is automatically generated
I wonder how to get LATEX table using xtable function from the following R

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.