在数据框中添加\ mathcal

时间:2019-02-21 15:29:57

标签: r latex r-markdown

我正在使用papaja软件包使用R和Rmarkdown制作可复制的手稿。我想为表做的一件事是使用mathmode使用符号。例如,我正在尝试创建一列变量,该变量是两个z \ mathcalc {M} symbols (e.g., $ \ mathcal {M} _1-\ mathcal {M} _2 $`的比较在Rmarkdown中:

enter image description here

但是,当我尝试将这些符号用作data.frame中的单元格时,R会发出警告:

table1 <- c("$\mathcal{M}_1 - \mathcal{M}_3$",
            "$\mathcal{M}_1 - \mathcal{M}_3$",
            "$\mathcal{M}_1 - \mathcal{M}_4$",
            "$\mathcal{M}_1 - \mathcal{M}_5$",
            "$\mathcal{M}_2 - \mathcal{M}_3$",
            "$\mathcal{M}_2 - \mathcal{M}_4$",
            "$\mathcal{M}_2 - \mathcal{M}_5$",
            "$\mathcal{M}_3 - \mathcal{M}_4$",
            "$\mathcal{M}_3 - \mathcal{M}_5$",
            "$\mathcal{M}_4 - \mathcal{M}_5$")
table2 <- c(49.273540, 198.383423, 198.956909, 198.846716, 198.933951, 198.200322, 197.778849,  11.361870,  14.627681,   7.231055)
table <- data.frame(table1,table2)

Error: '\m' is an unrecognized escape in character string starting ""$\m"

根据我在其他地方发现的在R中使用mathmode的发现,一种解决方案是使用两个斜杠,如下所示:

table1 <- c("$\\mathcal{M}_1 - \\mathcal{M}_3$",
            "$\\mathcal{M}_1 - \\mathcal{M}_3$",
            "$\\mathcal{M}_1 - \\mathcal{M}_4$",
            "$\\mathcal{M}_1 - \\mathcal{M}_5$",
            "$\\mathcal{M}_2 - \\mathcal{M}_3$",
            "$\\mathcal{M}_2 - \\mathcal{M}_4$",
            "$\\mathcal{M}_2 - \\mathcal{M}_5$",
            "$\\mathcal{M}_3 - \\mathcal{M}_4$",
            "$\\mathcal{M}_3 - \\mathcal{M}_5$",
            "$\\mathcal{M}_4 - \\mathcal{M}_5$")
table2 <- c(49.273540, 198.383423, 198.956909, 198.846716, 198.933951, 198.200322, 197.778849,  11.361870,  14.627681,   7.231055)
table <- data.frame(table1,table2)

到目前为止,太好了。没有错误讯息。但是,当我尝试使用apa_table函数通过papaja软件包将其格式化为乳胶表时,得到以下信息:

> apa_table(table)


\begin{table}[tbp]
\begin{center}
\begin{threeparttable}
\begin{tabular}{ll}
\toprule
table1 & \multicolumn{1}{c}{table2}\\
\midrule
\$\textbackslash{}mathcal\{M\}\_1 - \textbackslash{}mathcal\{M\}\_3\$ & 49.27\\
\$\textbackslash{}mathcal\{M\}\_1 - \textbackslash{}mathcal\{M\}\_3\$ & 198.38\\
\$\textbackslash{}mathcal\{M\}\_1 - \textbackslash{}mathcal\{M\}\_4\$ & 198.96\\
\$\textbackslash{}mathcal\{M\}\_1 - \textbackslash{}mathcal\{M\}\_5\$ & 198.85\\
\$\textbackslash{}mathcal\{M\}\_2 - \textbackslash{}mathcal\{M\}\_3\$ & 198.93\\
\$\textbackslash{}mathcal\{M\}\_2 - \textbackslash{}mathcal\{M\}\_4\$ & 198.20\\
\$\textbackslash{}mathcal\{M\}\_2 - \textbackslash{}mathcal\{M\}\_5\$ & 197.78\\
\$\textbackslash{}mathcal\{M\}\_3 - \textbackslash{}mathcal\{M\}\_4\$ & 11.36\\
\$\textbackslash{}mathcal\{M\}\_3 - \textbackslash{}mathcal\{M\}\_5\$ & 14.63\\
\$\textbackslash{}mathcal\{M\}\_4 - \textbackslash{}mathcal\{M\}\_5\$ & 7.23\\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{center}
\end{table}

没有产生我想要的表:

enter image description here

因此,总之,除了手动将$\mathcal{M}_1 - \mathcal{M}_2$粘贴到表中之外,我如何才能将其import React, { Component } from "react"; import { Text, TextInput, View, TouchableHighlight, StyleSheet, Button, FormData } from "react-native"; import Permissions from "react-native-permissions"; import ImagePicker from "react-native-image-crop-picker"; import axios from "axios"; var styles = StyleSheet.create({}); var msg = "Select Image"; var data; export default class API extends Component { constructor(props) { super(props); this.state = { name: "", price: "", size: "", description: "", image: "", popularity: "" }; } FormDataFunc() { let form = new FormData(); form.append("name", this.state.name); form.append("price", this.state.price); form.append("size", this.state.size); form.append("description", this.state.description); form.append("image", this.state.image); form.append("popularity", this.state.popularity); return form; return form; } onChange(e) { this.setState({ [e.target.name]: e.target.value }); } Submit() { axios({ method: "post", url: "http://192.168.0.102:3000/products", data: this.FormDataFunc, headers: { Accept: "application/json", "Content-Type": "application/x-www-form-urlencoded" }, body: this.FormDataFunc }) .then(() => { console.log("DONE!"); this.props.navigation.navigate("offersScreen"); }) .catch(err => { console.log(err); console.log(this.FormDataFunc); }); } componentDidMount() { Permissions.check("photo").then(response => { // Response is one of: 'authorized', 'denied', 'restricted', or 'undetermined' console.log(response); }); } render() { const image = () => { ImagePicker.openPicker({ multiple: false, includeBase64: true }).then(images => { console.log(images); this.setState({ images: { data: `\`${images.mime}\`;base64,\`${images.data}\`` } }); console.log(this.state.images); msg = "Selected"; }); }; return ( <View> <TextInput placeholder="Name" name="name" /> <TextInput placeholder="Price" name="price" /> <TextInput placeholder="Size" name="size" /> <TextInput placeholder="Description" name="description" /> <TouchableHighlight onPress={image} name="image"> <Text>{msg}</Text> </TouchableHighlight> <TextInput placeholder="Popularity" name="popularity" /> <TouchableHighlight title="Submit" onPress={this.Submit}> <Text>Send</Text> </TouchableHighlight> </View> ); } } 插入表中?我必须经常这样做,所以我想使用一种更简单的方式来分配值。

1 个答案:

答案 0 :(得分:1)

apa_table会将您的字符串转义为可以在LaTeX中照原样转录。这通常是您想要的,但您可以将escape = FALSE传递给apa_table

不幸的是,此参数的默认参数在此泛型函数的不同S3方法之间不一致。这可能是一个错误。