Knitr和图标题在HTML中(Knitr and Figure Caption in HTML)
knitr将参数fig.cap定义为
fig.cap:(NULL;字符)在LaTeX的图形环境中使用的图形标题(在\ caption {}中); 如果是NULL或NA,它将被忽略,否则图形环境将用于块中的图(在\ begin {figure}和\ end {figure}中输出)
但是,对于HTML输出以下工作:
--- title: "Caption Test" author: "Some Author" date: "February 18, 2016" output: html_document --- ```{r} library(ggplot2) ``` ```{r, fig.cap = c("This is caption 1", "This is caption 2")} ## Plot 1 qplot(carat, price, data = diamonds) ## Plot 2 qplot(carat, depth, data = diamonds) ```
意思是,每个数字在代码块参数
fig.cap = c("Caption 1", "Caption 2")
定义了正确的标题但是,要记住字幕 - 特别是长时间 - 当它们放置在大块选项中时,很难。 除了为每个图形创建两个单独的块并在字块外插入字幕之外,还有其他选项吗?
knitr defines the argument fig.cap as
fig.cap: (NULL; character) figure caption to be used in a figure environment in LaTeX (in \caption{}); if NULL or NA, it will be ignored, otherwise a figure environment will be used for the plots in the chunk (output in \begin{figure} and \end{figure})
However, for HTML output the following works:
--- title: "Caption Test" author: "Some Author" date: "February 18, 2016" output: html_document --- ```{r} library(ggplot2) ``` ```{r, fig.cap = c("This is caption 1", "This is caption 2")} ## Plot 1 qplot(carat, price, data = diamonds) ## Plot 2 qplot(carat, depth, data = diamonds) ```
meaning, each figures gets its correct caption defined in the code chunk argument
fig.cap = c("Caption 1", "Caption 2")
However, it is challenging to keep track of captions -especially if long- when they are placed inside the chunk options. Besides creating two separate chunks for each figure with captions inserted outside of the chunk, are there other options?
原文:https://stackoverflow.com/questions/35486935
最满意答案
亚历克斯,
我并不完全确定自己明白自己想要做什么,但是让我从我认为理解的地方对其进行刺探。
出于同样的理由(查看复杂性等),我经常在故事板中创建我的视图,然后从某个动作加载它们。 你可以做的是通过标识符来实例化视图控制器,如下所示:
FancyViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"FancyViewController"];
这假定你已经创建了一个叫做FancyViewController的UIViewController子类,并在storyboard中设置了你的视图控制器的类型。
现在,您可以将视图控制器显示在弹出窗口控制器中,或者将其推送到导航堆栈上。 你只需要确保你已经在故事板中为视图控制器设置了标识符。
此外,如果您使用popover控制器,并且每次触发操作时更新视图控制器属性,您都可能想要实例化视图控制器一次。 所以,如果它敲击触发弹出窗口的按钮,您的代码可能如下所示:
- (IBAction)didTapButtonToShowFancyViewController:(id)sender { if (![self fancyViewController]) { // fancyViewContrller is a property of type FancyViewController * fancyViewController = [[[self storyboard] instantiateViewControllerWithIdentifier:@"FancyViewController"]; // fancyViewPopoverController is also a property fancyViewPopoverController = [[UIPopoverController alloc] initWithContentViewController:fancyViewController]; } // Perform setup on the fancy controller you want to do every // time the action gets triggered here. Do initialization in the if // block above. // Now display the popover from the sender's frame. I'm assuming the // sender is a UIButton. [fancyViewPopoverController presentPopoverFromRect:[sender valueForKey:@"frame"] inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; }
动态设置弹出窗口的“锚点”的唯一方法是使用显式操作,该操作调用
presentPopoverFromRect:permittedArrowDirections:animated:
而不是segue。我希望有所帮助。 如果我误解了你想要做的事,请告诉我。
最好的祝福。
Alex,
I'm not completely sure I understand what you're trying to do, but let me take a stab at it from what I think I understand.
For the same reason you cite (view complexity, etc.), I often build out my views in the storyboard and then load them from some action. What you can do is instantiate the view controller by identifier with something like this:
FancyViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"FancyViewController"];
This assumes you have created a UIViewController subclass called FancyViewController and have set the type for your view controller in the storyboard.
Now, you can display the view controller in a popover controller or you can push it onto a navigation stack. You just need to make sure you've set the identifier for your view controller in the storyboard.
Also, you'll probably want to instantiate your view controller once if you use a popover controller and just update the view controllers properties each time the action gets triggered. So, if it's tapping a button that triggers the popover, your code might look like this:
- (IBAction)didTapButtonToShowFancyViewController:(id)sender { if (![self fancyViewController]) { // fancyViewContrller is a property of type FancyViewController * fancyViewController = [[[self storyboard] instantiateViewControllerWithIdentifier:@"FancyViewController"]; // fancyViewPopoverController is also a property fancyViewPopoverController = [[UIPopoverController alloc] initWithContentViewController:fancyViewController]; } // Perform setup on the fancy controller you want to do every // time the action gets triggered here. Do initialization in the if // block above. // Now display the popover from the sender's frame. I'm assuming the // sender is a UIButton. [fancyViewPopoverController presentPopoverFromRect:[sender valueForKey:@"frame"] inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; }
The only way to set the popover's "anchor" dynamically is to use an explicit action that calls
presentPopoverFromRect:permittedArrowDirections:animated:
instead of a segue.I hope that helps. Let me know if I've misunderstood what you're trying to do.
Best regards.
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
如何解决故事板移动(How to Dismiss a Storyboard Popover)[2023-06-29]
编辑:这些问题看起来像iOS 7.1 / Xcode 5.1.1一样修复。 (可能更早,因为我没有能够测试所有的版本。在iOS 7.0之后,自从我测试了一个版本之后)。当你从UIBarButtonItem创建一个UIBarButtonItem segue时,segue确保再次UIBarButtonItem隐藏popover而不是显示重复。 它适用于Xcode 6为iOS 8创建的新的基于UIPresentationController的弹出窗口。 由于我的解决方案可能对那些仍然支持较早版本的iOS版本的历史 ... -
您可能想要使用委托设计模式。 如果我理解你的情况,你可以通过以下方式完成: class MyTableViewController: UITableViewController { // ... weak var myViewControllerDelegate: MyViewController? // Make sure it's weak! .. or you know what you're doing, haha override func tableView(tabl ...
-
在Storyboard中放置一个视图,然后从代码中的PopOver中加载它?(lay out a view in Storyboard then load it in a PopOver from code?)[2021-12-20]
亚历克斯, 我并不完全确定自己明白自己想要做什么,但是让我从我认为理解的地方对其进行刺探。 出于同样的理由(查看复杂性等),我经常在故事板中创建我的视图,然后从某个动作加载它们。 你可以做的是通过标识符来实例化视图控制器,如下所示: FancyViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"FancyViewController"]; 这假定你已 ... -
将这样的popover存储在prepareForSegue中,然后放置一个断点以确保该方法正在触发。 self.myPopoverController = [(UIStoryboardPopoverSegue *)segue popoverController]; Store your popover like this in your prepareForSegue then place a breakpoint to make sure the method is firing. self.myPop ...
-
我有同样的问题,大多数在这里找到解决方案。 基本上,每次按下按钮以显示或关闭弹出按钮时,您都会更改按钮的动作。 这是我最终得到的代码: @interface FilterTableViewController : UITableViewController { UIPopoverController *editPopover; id saveEditSender; id saveEditTarget; SEL saveEditAction; } -(void)prepare ...
-
使用Storyboard(以及新的和改进的NSViewController),可以很容易地从许多不同的来源创建popover segues。 此图显示了最简单的示例; 一个文本字段的弹出窗口,根据按下的按钮而改变: Popover的View Controller被子类化以添加“name”变量,但您可以在视图中添加要绑定的任何对象。 主View Controller实现prepareForSegue函数。 根据发件人的对象,它将PopoverController的“name”属性设置为不同的值。 以下是使此示 ...
-
在Xcode Storyboard中使用Unwind Segue关闭Popover(Dismiss Popover using Unwind Segue in Xcode Storyboard)[2022-03-06]
展开segues使用运行时搜索,首先要求父视图控制器走上通过segue呈现的视图控制器链,直到找到正确的展开方法。 但是这里没有链条,因为popover是以编程方式创建的,而不是使用popover segue。 由于没有segue链接返回到父视图控制器,因此不会发生回调。 展开segue是一种抽象的委托形式,因此这类似于忘记设置委托而不接收任何回调。 解决方案是在Interface Builder中使用segue创建configChartTapped:而不是使用configChartTapped:方法以编程 ... -
您不需要任何代码来加载新视图。 您只需控制 - 从按钮拖动到要显示的控制器,然后选择segue类型。 如果带有按钮的控制器在导航控制器中,您可以选择按下或模态,如果不是,则需要选择模态。 You don't need any code to load a new view. You just control-drag from the button to the controller you want to present, and choose the segue type. If the control ...