1

I have a LaTeX table that I generate in R using stargazer. I include it via Insert -> File -> Child Document -> Type: Input. I have activated instant preview, and I ticked the box to show the preview of the table, but it does not work. I post the code of the table here. Maybe someone can help me with this. It would be very convenient to have the preview in the Lyx file without having to compile it.

I am using Windows 10 and Lyx version 2.3.0 rc2

% Table created by stargazer v.5.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: Mi, Feb 21, 2018 - 10:00:24
\begin{table}[!htbp] \centering 
  \caption{Regressions on daily returns} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}}lccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
\\[-1.8ex] & \multicolumn{3}{c}{Returns} \\ 
\\[-1.8ex] & (1) & (2) & (3)\\ 
\hline \\[-1.8ex] 
 $\Delta \mu_{t}$ & $-$0.002 &  & $-$0.003$^{**}$ \\ 
  & (0.001) &  & (0.001) \\ 
  & & & \\ 
 $\Delta \sigma^{2}_{t}$ &  & $-$0.010 & $-$0.015$^{**}$ \\ 
  &  & (0.006) & (0.006) \\ 
  & & & \\ 
 Constant & 0.002$^{*}$ & 0.002$^{*}$ & 0.002$^{**}$ \\ 
  & (0.001) & (0.001) & (0.001) \\ 
  & & & \\ 
\textit{N} & 1,402 & 1,402 & 1,402 \\ 
R$^{2}$ & 0.001 & 0.002 & 0.004 \\ 
Adjusted R$^{2}$ & 0.0002 & 0.001 & 0.002 \\ 
\hline 
\hline \\[-1.8ex] 
\multicolumn{4}{l}{\parbox[t]{7cm}{Regression for mean sentiment and variance of sentiment on $\log(p_{t})-\log(p_{t-1})$. The sample spans from 01.01.2011 to 07.11.2017. Values in parenthesis are HAC-robust Newey-West standard errors.}} \\ 
\multicolumn{4}{l}{*: p < 0.10, **: p < 0.05, ***: p <0.01} \\ 
\end{tabular} 
\end{table} 
  • 1
    Seems to work here if you remove the \begin{table} \caption{..}\label{...} and \end{table}, is that a useful workaround? (Also has the benefit that if you add the label via the LyX GUI instead of in code, the cross-reference will show up in the crossreference-manager.) – Torbjørn T. Feb 21 '18 at 9:55
  • Now it works, but I need to embed it also in a preview-environment. Thanks a lot! It is a useful workaround, because I can drop the table environment automatically using stargazer. This is also useful for the crossreference manager. – LyxUser12345 Feb 21 '18 at 10:32
1

If the .tex file is edited to remove the outer table environment as well as caption and label, the preview works. I.e. have just

\begin{tabular}{@{\extracolsep{5pt}}lccc} 
...
\end{tabular} 

(It was a bit finicky though, at least on my system. If I selected Show preview when first adding the child document, I had to go back to the inset settings and turn the preview off, and then on again, for it to appear, it didn't work right away. LyX 2.2.3 on Kubuntu.)

Adding table environment with caption and label via the LyX GUI has the added benefit that the table caption and label will show up in the Outline pane, and that the label will be available when insert cross-references.

LyX window

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.