You were on the right track, but you did not follow the Jörg's instructions completely.
First make sure that you add Jörg's preamble into your document preamble (in LyX: Document > Settings > Latex-Preamble):
% Packages for tables
\usepackage{booktabs}% Pretty tables
\usepackage{threeparttablex}% For Notes below table
% *****************************************************************
% siunitx
% *****************************************************************
\newcommand{\sym}[1]{\rlap{#1}} % Thanks to Joseph Wright & David Carlisle
\usepackage{siunitx}
\sisetup{
detect-mode,
group-digits = false,
input-symbols = ( ) [ ] - +,
table-align-text-post = false,
input-signs = ,
}
% Character substitution that prints brackets and the minus symbol in text mode. Thanks to David Carlisle
\def\yyy{%
\bgroup\uccode`\~\expandafter`\string-%
\uppercase{\egroup\edef~{\noexpand\text{\llap{\textendash}\relax}}}%
\mathcode\expandafter`\string-"8000 }
\def\xxxl#1{%
\bgroup\uccode`\~\expandafter`\string#1%
\uppercase{\egroup\edef~{\noexpand\text{\noexpand\llap{\string#1}}}}%
\mathcode\expandafter`\string#1"8000 }
\def\xxxr#1{%
\bgroup\uccode`\~\expandafter`\string#1%
\uppercase{\egroup\edef~{\noexpand\text{\noexpand\rlap{\string#1}}}}%
\mathcode\expandafter`\string#1"8000 }
\def\textsymbols{\xxxl[\xxxr]\xxxl(\xxxr)\yyy}
% *****************************************************************
% Estout related things
% *****************************************************************
\let\estinput=\input % define a new input command so that we can still flatten the document
\newcommand{\estwide}[3]{
\vspace{.75ex}{
\textsymbols% Note the added command here
\begin{tabular*}
{\textwidth}{@{\hskip\tabcolsep\extracolsep\fill}l*{#2}{#3}}
\toprule
\estinput{#1}
\bottomrule
\addlinespace[.75ex]
\end{tabular*}
}
}
\newcommand{\estauto}[3]{
\vspace{.75ex}{
\textsymbols% Note the added command here
\begin{tabular}{l*{#2}{#3}}
\toprule
\estinput{#1}
\bottomrule
\addlinespace[.75ex]
\end{tabular}
}
}
% Allow line breaks with \\ in specialcells
\newcommand{\specialcell}[2][c]{%
\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}
}
% *****************************************************************
% Custom subcaptions
% *****************************************************************
% Note/Source/Text after Tables
% The new approach using threeparttables to generate notes that are the exact width of the table.
\newcommand{\Figtext}[1]{%
\begin{tablenotes}[para,flushleft]
\hspace{6pt}
\hangindent=1.75em
#1
\end{tablenotes}
}
\newcommand{\Fignote}[1]{\Figtext{\emph{Note:~}~#1}}
\newcommand{\Figsource}[1]{\Figtext{\emph{Source:~}~#1}}
\newcommand{\Starnote}{\Figtext{* p < 0.1, ** p < 0.05, *** p < 0.01. Standard errors in parentheses.}}% Add significance note with \starnote
You said you did that but Jörg made some refinements in his follow-up posts. I took this from his sample document. Note that I included the threeparttablex
package instead of threeparttable
, since the former also supports longtable
(for tables spanning more than one page, should you need that). For this example, however, this does not matter.
e-birk is right that not everyone has access to Stata, but for those that do, it helps to add a MWE that makes use of the example datasets installed with Stata (help sysuse
). So I adjusted your example like this:
sysuse auto
regress mpg weight length foreign, robust // specification with 'foreign'
eststo C1
regress mpg weight length, robust // specification without 'foreign'
eststo C2
regress price weight length foreign, robust // specification with 'foreign'
eststo C3
regress price weight length, robust // specification without 'foreign'
eststo C4
Now export the table from Stata as a fragment and without the table notes (we add these later into the LaTeX/LyX document). The right esttab
command should be something like this:
esttab C1 C2 C3 C4 using test_tex, booktabs fragment replace ///
se(%3.2f) b(3) label indicate(Controls=foreign) ///
star(* 0.1 ** 0.05 *** 0.01) nonotes nomtitles drop(_cons) ///
mgroups("mpg" "weight", pattern(1 0 1 0) ///
prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
Note that I added the fragment option. I also reformated the command a little. This way you can just add , ///
before using
in the first line to test your table in Stata first (e.g. to see whether labels are correct, etc.).
Finally, include the table in LyX with this (adjust accordingly):
\begin{table}\centering
\begin{threeparttable}
\caption{Table with Better Notes and Better Symbols}
\estauto{test_tex}{4}{c}
\Figtext{Some basic text about the table.}
\Fignote{Standard errors corrected for heteroskedasticity in brackets. \\
\textit{* p < 0.10, ** p < 0.5, *** p < 0.01}}
\Figsource{auto.dta (Stata example dataset)}
% \Starnote
\end{threeparttable}
\end{table}
You can insert this into your LyX document with Evil Red Text (Insert > Tex-Code) or use a .tex document and insert that as a file into your document.
I added the p-value note directly, but you could also use the \Starnote
command (useful if you have multiple tables with the same p-symbols). Adjust the p-values on the last line of the preamble accordingly.
I also used the center alignment {c}
in \estauto{test_tex}{4}{c}
instead of the decimal alignment {S}
, since the latter seems to choke on the Controls row. I am not very familiar with the siunitx
package, so I might be wrong here or there might be an easy fix.
Obviously, this is mostly Jörg's code, he deserves the credit.
You can use minipage
s as you first tried, if you add the capt-of
(or caption
) package and write the caption in an ERT using captionof
command, which has the syntax
\captionof{<float type>}{<caption>}
So, in LyX:
Document --> Settings --> LaTeX preamble, add either
\usepackage{capt-of}
(or \usepackage{caption}
)
- Insert a figure float, with Insert --> Float --> Figure or the button on the toolbar.
- Delete the caption that is there by default (just place the cursor outside it, and hit backspace or delete).
- Add two
minipage
s with Insert --> Boxes --> Frameless. Add the second one immediately after the first one, do not hit enter after the first one.
- Set the width of both to just below half the line width, e.g. 49% of the line width.
- In the minipage where you want the figure, add a new caption with Insert --> Caption. Add the image above it, as you normally would.
In the minipage where you want the table, add an ERT with Ctrl + L or Insert --> TeX Code, and write
\captionof{table}{Your table caption}
Add the table below the caption as you normally would.
Optionally, you could write
\captionsetup{type=table}
in the ERT, and add the caption outside the ERT with Insert --> Caption. Make sure the ERT is placed before the caption. Note that this will not change the caption type in the LyX GUI, there you'll still have two figure captions, but in the PDF it will be correct. This also makes it easier to add cross references or citations in the caption, as you can use the GUI for that.
You may have to change the vertical alignment of the minipages as well, which you can do in the settings for the Inset. In the image below, the right minipage has the vertical alignment for the Box set to Middle, all other vertical alignments are set to Top.
Best Answer
The width of the tabular can be set by right-clicking in it, selecting More --> Settings. For the Table-wide settings set the width to 100% of text width.
The distance between the caption text and table/figure can be set with the
skip=<distance>
option tocaption
, so you could add that option, e.g.but that will affect the figures as well. Instead, do this:
This will change that skip for just the table captions.
I cannot say why the font size is different. Possibly some other package you're loading that interferes. If it is still a problem, I recommend asking a new question about just this issue.