Labels in xtable captions for crossreferencing in lyx

风流意气都作罢 提交于 2019-12-06 06:35:06

问题


I am using pgfsweave with Lyx 1.6.8 and xtable. providing table captions by

<<result=tex>>=
print(xtable(<dataframe>,caption="Here is my caption"))
@.

How can I insert a label into the table caption that I can crossreference in the text from the lyx>Insert>Cross-reference menu?

I have tried to insert>float>table and inserted print(xtable(<dataframe>,floating=FALSE)) and "Here is my caption" in the Table caption inner frame but this results in (literally):

[float Table:
<...Table ...>
[Table 2: "Here is my caption" ] ]

Even a barefoot workaround to crossreference

<<result=tex>>=
print(xtable(<dataframe>,caption="Here is my caption",label = "tab:one"))
@

from an ERT-box would help.


回答1:


SOLVED: Just use TWO arguments in the xtable-function call in the R-code:

xtable(<dataframe>
, caption = "My caption\\label{tab:MyTable1}"
,label="tab:MyTable1")

The \\label{tab:MyTable1} inside the caption is changed to \label{tab:MyTable1} by R and then interpreted by LaTeX.

The argument label="tab:MyTable1" is ignored by R and therefore at your disposal to trick Lyx into allowing for crossreferencing to the label table label. Use Insert>label to insert the label "tab:MyTable1" (excluding the quotes) here.



来源:https://stackoverflow.com/questions/4564698/labels-in-xtable-captions-for-crossreferencing-in-lyx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!