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 8316051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:16:14+00:00 2026-06-08T21:16:14+00:00

I am trying to print out this table with xtable() , which is reproduced

  • 0

I am trying to print out this table with xtable(), which is reproduced below:

                   X            B.1            B.2            B.3
1        (Intercept) -1.669 (0.093) -1.701 (0.094) -1.774 (0.121)
2          SEXFemale  -0.46 (0.023)  -0.386 (0.04)  -0.274 (0.17)
3    SEXFemale:BLACK                                0.132 (0.163)
4    SEXFemale:ASIAN                               -0.063 (0.089)
5 SEXFemale:HISPANIC                               -0.128 (0.074)

But I would like to override the way the first column is printed. Is it possible to include latex commands in xtable() or some other function to do this? Specifically, I would like the first column to be :

    X
Male: Female
Female X Black
       X Asian
       X Hispanic

i.e. I would like to write a \phantom{} switch into the column so that the spacing comes out right.

  • 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-06-08T21:16:15+00:00Added an answer on June 8, 2026 at 9:16 pm

    You can use a regular expression to insert the \phantom{} into your table before calling xtable():

    Recreate your data:

    x <- structure(list(X = structure(c(1L, 2L, 4L, 3L, 5L), .Label = c("(Intercept)", 
                                                                        "SEXFemale", "SEXFemale:ASIAN", "SEXFemale:BLACK", "SEXFemale:HISPANIC"
    ), class = "factor"), B.1 = structure(c(3L, 2L, 1L, 1L, 1L), .Label = c("", 
                                                                            "-0.46 (0.023)", "-1.669 (0.093)"), class = "factor"), B.2 = structure(c(3L, 
                                                                                                                                                     2L, 1L, 1L, 1L), .Label = c("", "-0.386 (0.04)", "-1.701 (0.094)"
                                                                                                                                                     ), class = "factor"), B.3 = structure(c(4L, 3L, 5L, 1L, 2L), .Label = c("-0.063 (0.089)", 
                                                                                                                                                                                                                             "-0.128 (0.074)", "-0.274 (0.17)", "-1.774 (0.121)", "0.132 (0.163)"
                                                                                                                                                     ), class = "factor")), .Names = c("X", "B.1", "B.2", "B.3"), class = "data.frame", row.names = c(NA, 
                                                                                                                                                                                                                                                      -5L))
    

    The regex:

    x$X <- gsub("SEXFemale:", "\\\\phantom{Female} X ", x$X)
    x$X <- gsub("SEXFemale", "Female", x$X)
    
    
    library(xtable)
    xx <- print(xtable(x), print.results = FALSE, include.rownames = FALSE,
            sanitize.text.function=function(x)x)
    cat(xx)
    

    The resulting text:

    % latex table generated in R 2.15.0 by xtable 1.7-0 package
    % Thu Jul 26 17:10:05 2012
    \begin{table}[ht]
    \begin{center}
    \begin{tabular}{llll}
      \hline
    X & B.1 & B.2 & B.3 \\ 
      \hline
    (Intercept) & -1.669 (0.093) & -1.701 (0.094) & -1.774 (0.121) \\ 
      Female & -0.46 (0.023) & -0.386 (0.04) & -0.274 (0.17) \\ 
      \phantom{Female} X BLACK &  &  & 0.132 (0.163) \\ 
      \phantom{Female} X ASIAN &  &  & -0.063 (0.089) \\ 
      \phantom{Female} X HISPANIC &  &  & -0.128 (0.074) \\ 
       \hline
    \end{tabular}
    \end{center}
    \end{table}
    

    And the final output:

    enter image description here

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

Sidebar

Related Questions

In the code below, I am trying to print out a 1-column, 25-row table,
I'm trying to print out a list of products on a page. This is
I am trying to print out yes if a boolean table field from a
I am trying to print out a table of values in Prolog. Currently I
I am trying to sort all of this information into a small table which
Trying to figure out how I can do this properly. The print_r looks like
I am trying to remove substring out of variable using sed like this: PRINT_THIS=`echo
I am trying to print out true if there is such letter/word and false
I am trying to print out documents in various different orders. Right now I
I am trying to print out the names of each person in the loop.

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.