LyX ⇒ Two tables on the same line with xtable/knitr
Two tables on the same line with xtable/knitr
Hello everyone.
I would like to get two tables on the same line due to their small size. I generate them with xtable via knitr chunks and they are placed one above the other by default. I tried to use multicol but the tables simply disappear. I also tried to make a simple table with one line and two columns and put the knitr chunks inside but this send me an error.
Does anyone know a way to do this in Lyx ?
Sincerely
Hive
I would like to get two tables on the same line due to their small size. I generate them with xtable via knitr chunks and they are placed one above the other by default. I tried to use multicol but the tables simply disappear. I also tried to make a simple table with one line and two columns and put the knitr chunks inside but this send me an error.
Does anyone know a way to do this in Lyx ?
Sincerely
Hive
NEW: TikZ book now 40% off at Amazon.com for a short time.

-
- Site Moderator
- Posts: 542
- Joined: Sat Sep 01, 2012 6:38 am
Re: Two tables on the same line with xtable/knitr
First create a table float: insert > float > table. Then do the same thing. Now you have a subfloat. Create another subfloat (insert a table float inside the parent float) and you have two subfloats. Put your knitr chunks in there.
Two tables on the same line with xtable/knitr
Hi and thanks for the answer.
I tried to do what you said but it still doesn't work. In attach, a mwe of what I did. Maybe I missed something ?
I looked at knitr chunk options but didn't find something usefull to set.
I tried to do what you said but it still doesn't work. In attach, a mwe of what I did. Maybe I missed something ?
I looked at knitr chunk options but didn't find something usefull to set.
- Attachments
-
- mwe_tables.tex
- (3.81 KiB) Downloaded 368 times
-
- mwe_tables.lyx
- (4.53 KiB) Downloaded 319 times
-
- Site Moderator
- Posts: 542
- Joined: Sat Sep 01, 2012 6:38 am
Re: Two tables on the same line with xtable/knitr
I'm happy to take a look but please make a *minimal* example. Read here for more information:
http://wiki.lyx.org/FAQ/MinimalExample
The example that you posted has a lot of preamble code. There are also other document settings that are non-standard. Can you create a new document and try to only modify the document settings that are necessary to reproduce the problem?
http://wiki.lyx.org/FAQ/MinimalExample
The example that you posted has a lot of preamble code. There are also other document settings that are non-standard. Can you create a new document and try to only modify the document settings that are necessary to reproduce the problem?
Re: Two tables on the same line with xtable/knitr
Sorry. Here another MWE.
- Attachments
-
- mwe_tables.lyx
- (3.11 KiB) Downloaded 349 times
-
- Site Moderator
- Posts: 542
- Joined: Sat Sep 01, 2012 6:38 am
Two tables on the same line with xtable/knitr
Thanks for taking the time to make a clean MWE!
First, if you look at the source code (View > Source), you will see
knitr needs to have it's beginning delimiter and end delimiter on new lines. LyX now actually knows that knitr needs to be on its own line if you use the Insert > Custom Insets > Chunk because LyX knows that inside that special inset is knitr code. It does not know whether what is inside ERT is LaTeX or knitr code so it does not ensure that it is on its own line. However, you can work around this by just adding a new line at the end (but inside) your ERTs.
Second, xtable produces a floating environment by default. Since you are having LyX take care of the floats in this case, we need to tell xtable to not use a float (and just produce a fixed table). We do this with:
If those changes don't fix the problem for you, make the changes and post a new MWE with the changes I suggest.
First, if you look at the source code (View > Source), you will see
Code: Select all
@}
Second, xtable produces a floating environment by default. Since you are having LyX take care of the floats in this case, we need to tell xtable to not use a float (and just produce a fixed table). We do this with:
Code: Select all
print.xtable(m_table, floating = FALSE)
Re: Two tables on the same line with xtable/knitr
Thanks a lot, it works by combining custom insert and "floating=FALSE" xtable option.
I also find another solution with two minipages side by side : insert -> box -> without border (maybe not the exact names, I work on french lyx version). Put your knitr chunk inside and then set the width of your minipages less than 50 in order to let them share the same line of the page.
In attach an example of each cases.
Thank you for our help
I also find another solution with two minipages side by side : insert -> box -> without border (maybe not the exact names, I work on french lyx version). Put your knitr chunk inside and then set the width of your minipages less than 50 in order to let them share the same line of the page.
In attach an example of each cases.
Thank you for our help

- Attachments
-
- mwe_tables.lyx
- (4.6 KiB) Downloaded 377 times